Mys 1.3.6 Give Treasures/Held Items to Pets Script

Forum
Last Post
Threads / Messages
Thank you and yes rest your hands :)

I will get that and upload this morning.
 
When you say ownedadoptsview, do you mean ownedadoptableview ?

and then changing this line in ownedadoptsview to use 0 instead of noitem

if ($ownedAdopt->getTreasure() != "0") {
$treasure = new OwnedItem(($ownedAdopt->getTreasure()), $mysidia->user->getID());
$links->add(new Comment("<div style='display:flex;align-items:center;'>
<p><img src='{$treasure->getImageURL()}' alt='{$treasure->getItemname()}'></p>
<p><b>Treasure:</b> {$treasure->getItemname()}</p>
</div>"));
} else {
$links->add(new Comment("<div><p><b>Treasure:</b> None</p></div>"));
}



I cant find an ownedadoptsview .. I may just be so burned out at this point i cant see it.

By now I likely have forgotten or mistyped a few things, this has been epic .. there are likely things I have omitted now I shouldn't have, or vice versa. :D
 

Attachments

  • ownedadoptableviewmodel.php
    2.2 KB · Views: 3
Last edited:
Sorry, yeah you sent all the files and I'm not seeing how it should not work. I'm going out on a limb here because I know you have bootstrap mod installed and I don't, so you can try getting rid of the inline styling, this is how I did it:

Code:
    $links = new Division(NULL, "right");
        $links->add(new Comment("<br>{$ownedAdopt->getName()}'s Links:<br>"));
        $treasure = $this->getField("treasure");
        if ($ownedAdopt->getTreasure() != "0") {
            $links->add(new Image($treasure->getImageURL()));
            $links->add(new Comment("Treasure: {$treasure->getItemname()}"));
            $links->add(new Image("templates/icons/package-delete.png"));
            $links->add(new Link("myadopts/treasure/{$ownedAdopt->getID()}/confirm", " Remove Treasure", TRUE));
        } else {
            $links->add(new Comment("Treasure: None"));
        }
        $links->add(new Image("templates/icons/add.gif"));

then you can make a class in your CSS file named right (or whatever you want to name it, just change the name in the new Division function) and put the flex and all the styling in there.

Also, in the database, I have my treasure field set to null even though there is a default of 0

Finally, we need to get all errors showing up on your test server, not just the ones mysidia allows. This will show you the error message when pages don't load so you are not frustrated when mysidia is not telling you what is wrong. In your php.ini file go to the section that has this

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; This directive informs PHP of which errors, warnings and notices you would like
; it to take action for. The recommended way of setting values for this
; directive is through the use of the error level constants and bitwise
; operators. The error level constants are below here for convenience as well as
; some common settings and their meanings.
; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
; those related to E_NOTICE and E_STRICT, which together cover best practices and
; recommended coding standards in PHP. For performance reasons, this is the
; recommend error reporting setting. Your production server shouldn't be wasting
; resources complaining about best practices and coding standards. That's what
; development servers and development settings are for.
; Note: The php.ini-development file has this setting as E_ALL. This
; means it pretty much reports everything which is exactly what you want during
; development and early testing.
;
; Error Level Constants:
; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
; E_ERROR           - fatal run-time errors
; E_RECOVERABLE_ERROR  - almost fatal run-time errors
; E_WARNING         - run-time warnings (non-fatal errors)
; E_PARSE           - compile-time parse errors
; E_NOTICE          - run-time notices (these are warnings which often result
;                     from a bug in your code, but it's possible that it was
;                     intentional (e.g., using an uninitialized variable and
;                     relying on the fact it is automatically initialized to an
;                     empty string)
; E_STRICT          - run-time notices, enable to have PHP suggest changes
;                     to your code which will ensure the best interoperability
;                     and forward compatibility of your code
; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
;                     initial startup
; E_COMPILE_ERROR   - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR      - user-generated error message
; E_USER_WARNING    - user-generated warning message
; E_USER_NOTICE     - user-generated notice message
; E_DEPRECATED      - warn about code that will not work in future versions
;                     of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
;
; Common Values:
;   E_ALL (Show all errors, warnings and notices including coding standards.)
;   E_ALL & ~E_NOTICE  (Show all errors, except for notices)
;   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.)
;   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors)
; Default Value: E_ALL
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; http://php.net/error-reporting
error_reporting = E_ALL

Notice my very last without the semicolon line says
error_reporting = E_ALL

Make sure yours is set to E_ALL
 
Last edited:
Thank you for all this! :) yes I will be working on this and give it a try over the weekend .. for this site, I am actually using Main as the theme ...

I'm glad I didnt have any glaring errors, I can't figure it out either.

I may just take a break from this mod and finish the sim, its just not wanting to work for me, for some reason!
 
Would you allow me to see your inventorycontroller and inventoryview files?
Also your service\applicationservice\helper\itemtablehelper

I'm wondering if it's simply not inputting the correct id when you give the item from inventory
 
Would you allow me to see your inventorycontroller and inventoryview files?
Also your service\applicationservice\helper\itemtablehelper

I'm wondering if it's simply not inputting the correct id when you give the item from inventory


Of course! Let me get those for you tonight :) Actually I have even manually input the ID into the database .. its supposed to be the item ID number right?
 
Here you go ! Have been getting no errors with this at all.

As far as I know, it needs the item number from items table in database right?

I have tried putting that in myself and still no go ...
 

Attachments

  • itemtablehelper.php
    3.6 KB · Views: 0
  • inventoryview.php
    5.6 KB · Views: 1
  • inventorycontroller.php
    4 KB · Views: 0
Okay, found the error seems to be here, in myadoptsview:


Code:
        $links->add(new Comment("<br>{$ownedAdopt->getName()}'s Links:<br>"));
        $treasure = $this->getField("treasure");
        if ($ownedAdopt->getTreasure() != "0") {
            $links->add(new Comment("<div style='display:flex;align-items:center;'>
                <p><img src='{$treasure->getImageURL()}' alt='{$treasure->getItemname()}'></p>
                <p><b>Treasure:</b> {$treasure->getItemname()}</p>
            </div>"));
            $links->add(new Image("templates/icons/package-delete.png"));
            $links->add(new Link("myadopts/treasure/{$ownedAdopt->getID()}/confirm", " Remove Treasure", TRUE));
        } else {
            $links->add(new Comment("<div><p><b>Treasure:</b> None</p></div>"));


It shows an error here for some reason, under all that, on the php page:


Code:
    public function stats(){
        $ownedAdopt = $this->getField("ownedAdopt");

If I remove the treasure block of code, all is well, and myadopts page loads.

If I put it back in, nope! So there's the glitch somewhere ...


Where exactly should I have this code inserted? I have it placed right after this:



Code:
    public function manage(){    
        $document = $this->document;    
        $ownedAdopt = $this->getField("ownedAdopt");
        $adoptbackground = "{$ownedAdopt->getAdoptBackground()}";
        $background = new Image($adoptbackground);
        $background->setType("background");
        $image = $this->getField("image");
        $document->setTitle("Managing {$ownedAdopt->getName()}");

        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);

        $document->add($petImage);


as far as I can tell, the other code at the very bottom of the page seems okay.
 
Last edited:
Did you try getting rid of the inline styling with my updated code? Try this first because it uses mysidia's native functions to pull the item and image data instead of forcing inline html and css to do it. Mysidia is made to work better with its own functions than with forcing inline styles.

Code:
        $links = new Division(NULL, "right"); //you can rename "right" to "links" or whatever else you call it, just make sure your CSS to style it is also named the same thing
        $links->add(new Comment("<br>{$ownedAdopt->getName()}'s Links:<br>"));
        $treasure = $this->getField("treasure");
        if ($ownedAdopt->getTreasure() !== "0") {
            $links->add(new Image($treasure->getImageURL()));
            $links->add(new Comment("Treasure: {$treasure->getItemname()}"));
            $links->add(new Image("templates/icons/package-delete.png"));
            $links->add(new Link("myadopts/treasure/{$ownedAdopt->getID()}/confirm", " Remove Treasure", TRUE));
        } else {
            $links->add(new Comment("Treasure: None"));
        }

I noticed all the rest of your code is using $document->add() (THIS IS WHERE THE ERROR IS, I FIGURED IT OUT) where mine is using $links->add() and so you need this after the links:

$document->add($links);

I made my links into a new division to move them to the right of the page, so if you don't want that, you can try this instead

Code:
        $document->add(new Comment("<br>{$ownedAdopt->getName()}'s Links:<br>"));
        $treasure = $this->getField("treasure");
        if ($ownedAdopt->getTreasure() !== "0") {
            $document->add(new Image($treasure->getImageURL()));
            $document->add(new Comment("Treasure: {$treasure->getItemname()}"));
            $document->add(new Image("templates/icons/package-delete.png"));
            $document->add(new Link("myadopts/treasure/{$ownedAdopt->getID()}/confirm", " Remove Treasure", TRUE));
        } else {
            $document->add(new Comment("Treasure: None"));
        }
 
Last edited:
Oh Wow, I will try that!!

Thank you, I am crossing my fingers! I am using the Main theme, for this site -- going to try it tomorrow :)
 
Welp, its crazy.

Made all the changes, the My Adopts manage loads fine ... if the treasure field says 0.

The second any number goes in, fail, page won't load.

So it's not getting what it wants, item number wise.

Is the ID number supposed to be that, from the item number itself?

I am baffled. Thats all thats killing it, it's loading fine till there is an actual number in the ownedadoptables treasure field .... 'Give' is working fine, and inserts the ID number of the item just fine .. and then ..

Bam!! That's what kills it :D



ALSO : Not sure if this is a clue but I was able to add 'Treasure' to the list of things shown in My Adopts, in the table view - and it popped up the number just fine.

It doesn't show an image or anything of course, but it does pull the item number. I just did this simple addition (after adding it to the list):


Code:
  $cells->add(new TCell($ownedAdopt->getTreasure()));
 
Last edited:
That's so strange, the treasure field in the view should send the treasure object so you can use anything from it, not just the ID. It looks like it's not working at the controller level now. We know the code is putting the item id into the treasure field, but it's not being passed to the view as an object.

I think it's passing over the if statement and just returning the else somehow, so you are getting the ID from the ownedadoptable table, but not the object from new OwnedItem().

This is from myadoptscontroller

Code:
    public function manage($aid){
        $mysidia = Registry::get("mysidia");
        $this->initOwnedAdopt($aid);
        if ($this->adopt->getTreasure() !== "0") {
            $this->treasure = new OwnedItem(($this->adopt->getTreasure()), $mysidia->user->getID());
        }else {
            $this->treasure = $this->adopt->getTreasure();
        }
        $this->setField("ownedAdopt", $this->adopt);
        $this->setField("image", $this->adopt->getImage(Model::GUI));
        $this->setField("ownedAdopt", new OwnedAdoptableViewModel($this->adopt));
        $this->setField("treasure", $this->treasure ? $this->treasure : NULL);
    }

It gets the new OwnedItem from the name space, which you seem to have in your controller

use Model\DomainModel\OwnedItem;

If you want to leave your code functioning for now while we keep testing what's going on, you can try to use this as your else statement:

}else {
$this->treasure = "0";
}

I tested this and it's working on my site so this change shouldn't hurt as it won't try to pass the ID of the item if it's not a new OwnedItem object. This can help us at least narrow down if it is the object not being passed.
 
Last edited:
Very good idea, I think I will move on from this now, we've put a huge amount of time and energy into it, and it's still confusing!

Thank you for all your efforts, I really appreciate them!!

I can live without this mod if need be, will focus more now on getting layers to work I think -- at least for now :)
 
Very good idea, I think I will move on from this now, we've put a huge amount of time and energy into it, and it's still confusing!

Thank you for all your efforts, I really appreciate them!!

I can live without this mod if need be, will focus more now on getting layers to work I think -- at least for now :)
In looking back through your files I noticed that this function was missing in your myadoptscontroller

Code:
    public function treasure($aid, $confirm = NULL){
        $mysidia = Registry::get("mysidia");
        $this->initOwnedAdopt($aid);
        if($confirm){
            if(!$aid) $this->index();
            $this->adopt->takeTreasure(Model::UPDATE);
        }
        $this->setField("adopt", $this->adopt);
        $this->setField("image", $this->adopt->getImage(Model::GUI));
        $this->setField("confirm", $confirm ? new MysString($confirm) : NULL);
    }

If you tried to change the item without it, you would get an error or a blank page. It still doesn't explain why new OwnedItem isn't being sent if you have an item ID that is not 0, but I thought I would mention it.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top