Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2017, 02:46 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 65,634
Dinocanid is on a distinguished road
Default Getting name of random item

I'm having a problem with telling the user what item(s) they're getting. In short a random item is chosen from a list of items and given to the user. Whenever I try to get the name of the item I get an error. Here's the shortened version of the code:
PHP Code:
$random mt_rand(1,3);

$Cnum mt_rand(1,5);
                            switch (
$Cnum){ 
                                case 
1$Citem "ball"; break; //Common items
                                
case 2$Citem "ball"; break; 
                                case 
3$Citem "ball"; break; 
                                case 
4$Citem "ball"; break; 
                                case 
5$Citem "ball"; break; 
                            }
if(
$random == 1){
$newitem1 = new StockItem($Citem);
                        
$newitem1->append(1$mysidia->user->username);
                        
$document->add(new Comment("Congratulations! You earned a {$newitem1}!"));
                        return;

(For testing purposes, the only item is a ball. The error also appears if the number is 2 or 3)

If I just get {$Citem} as the item name then it works fine, but I want the words to match the items given, not be randomly chosen.
__________________

Last edited by Dinocanid; 05-07-2017 at 02:48 PM. Reason: Forgot some parts
Reply With Quote
  #2  
Old 05-17-2017, 07:23 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 65,634
Dinocanid is on a distinguished road
Default

Since I got error messages back, I was able to find this as the error:
Quote:
Catchable fatal error: Method StockItem::__toString() must return a string value in /home/adopttes/public_html/view/treasureview.php on line 103
I tried using this like strval and (string) but that didn't work.

EDIT: I was able to fix it! I had to use this to get the name of the item:
Quote:
$ni1_name = $newitem1->itemname;
$document->add(new Comment("Congratulations! You earned a {$ni1_name} !"));
__________________

Last edited by Dinocanid; 05-17-2017 at 08:06 PM.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:06 AM.

Currently Active Users: 9691 (0 members and 9691 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636