![]() |
Loading Variables into Objects
Ok, here's what Im' doing, I'm loading variables from a text file into an object then I'm using a for each loop to go through each var starting with "whatever" like this"
PHP Code:
PHP Code:
PHP Code:
(What I'm doing is creating an item system using text files. :D |
getstringkeys() accepts this., thiso., player., playero. etc., you can't do "anyobjectname.varname" though. For that you would need to use the with-command like
PHP Code:
|
Quote:
Seeing as how a friend of mine told me, PHP Code:
Edit: But if I did: Here's what I'm doing: PHP Code:
|
Quote:
It is bad practice in general, and you should really just use with ( item ). By glancing at your script, however, you seem to be making things hard for yourself. Why don't you use the index numbers? PHP Code:
|
getDynamicVarNames()?
|
Basically, I have loaded variables from a text file into invcontents.
There maybe one or more variables in the text file starting with the prefix "inv_" now, then it uses the for loop to go through everything that starts with, "inv_". After that it checks what text is after "inv_". Like for example, in the text file I might have this: inv_item=name,icon,power,blah After I check if "item=" is after inventory or not or any of the other words after it, I'm creating a substring of everything after the "=" and tokenizing it to turn it into an array. This is what I'm trying to do, put all the information in the text file AFTER the "itemname=" into an array. What Stefan suggested, so something like this would be fine? PHP Code:
|
Quote:
|
Quote:
'inv_itemnamehere=' Like, 'inv_item=Name,ID,Icon' I'm trying to get all that information after item, or weapon --which is represented by 'i'-- and put it into an array. |
Hence like I said, everything after 'inv_', what your doing is right so far. Just use:
PHP Code:
|
*sigh*
I'm NOT using a database, it's an object dude, and I'm trying to return the information AFTER 'inv_tempi='. 'temp.i' stands for either "item=" or "weap=" and the information after the "=" is what I'm trying to get and pur into an array. |
Load the arrays first
PHP Code:
|
Quote:
I really don't get this TEXT FILE BELOW [TEXTFILE] inv_item=Name,Icon,ID inv_item=Name,Icon,ID inv_weap=Name,Icon,ID [/TEXTFILE] I load those vars from the text file into an object! NOW, OBJECT WITH BOLD [OBJECT] inv_item=Name,Icon,ID inv_item=Name,Icon,ID inv_weap=Name,Icon,ID [/OBJECT] Everything that's bolded and underlined, is what I'm trying to get from what I loaded into the object! I loaded inv_item=blah into the object, now I'm trying to get "blah" back. |
I'm not sure if that will work, your just overwriting the previous object. I would suggest 'item_id=Name, Icon'
|
Quote:
Also, a more sensible question would be, if, when I load "inv_item=Blah,Blah1,Blah2" from the text file into the object, does it become an array? E: Oh, it does! Thanks for helping, and sorry for flipping out on you guys. Just got quite frustrated. >_< |
Quote:
|
inv_item=Blah,Blah1,Blah2
If you meant something like inv_item1337=id=1,quantity=1,foo=3 etc. You could use getDynamicVarNames(); Use a str.starts(); and then use a ( "varname_" @ ITEMNAME ) = array; then when accessing you could create a TStaticVar() and obj.LoadVarsFromArrays(); |
Putting the variable names are part of the item array data is very bad in my opinion. What I've done with more simple systems like that is set a serverr variable that show whats at each index:
serverr.itemvars_<typename>=id,qty,name,image,weig ht clientr.item<number>=23,1,"Fancy Sword",fancysword.png,5000 Then you use function like getitemvar(id, varname) and return the item index that matches the index of the varname in the serverr string. Edit: With the simplest system I would have the type of item as the first variable, then I would find the right variable list for that type with a function before continuing so all items didn't require a master list. |
| All times are GMT +2. The time now is 11:11 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.