Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-10-2007, 09:16 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
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:
blah = new TStaticVar();
blah.loadVars("thistextfile.arc"
Now my questions is do I do this...

PHP Code:
for (igetstringkeys("inv_")); 
Or this....

PHP Code:
for (igetstringkeys("blah.inv_")); 
Forgive me if it's a really simple or unintelligent questions, I just sort of started understanding objects today and I figured this would be somewhat of a cakewalk. :P

(What I'm doing is creating an item system using text files.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #2  
Old 04-10-2007, 10:08 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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:
with (objectname) {
  for (
keygetstringkeys("this.inv_"))
    ...

Reply With Quote
  #3  
Old 04-10-2007, 10:18 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Stefan View Post
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:
with (objectname) {
  for (
keygetstringkeys("this.inv_"))
    ...

That's interesting. >.>

Seeing as how a friend of mine told me,

PHP Code:
for (keygetstringkeys("objectname.inv_")) 
Would work.

Edit: But if I did:

Here's what I'm doing:

PHP Code:
public function inventory()
{
  
invcontents = new TStaticVar();
  
invcontents.loadVars("levels/player_" player.account ".arc");
    for (
igetstringkeys("inv_"))
    {
      if (
== "item=")
      {
        
tokens getstringkeys("invcontents.inv_" i).substring(22).tokenize(",");
      }
      else if (
== "wep=")
      {
        
//stuff
      
}
      else if (
== "keyitem=")
      {
        
tokens getstringkeys("invcontents.inv_" i).substring(25).tokenize(",");
      }
      else if (
== "clothes=")
      {
        
tokens getstringkeys("invcontents.inv_" i).substring(25).tokenize(",");
      }
    }
  } 

Also, doing what you said and using, with, would I have to put "this.inv_" or could I just do "inv_".
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.

Last edited by killerogue; 04-10-2007 at 10:31 AM..
Reply With Quote
  #4  
Old 04-10-2007, 02:10 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by killerogue View Post
That's interesting. >.>

Seeing as how a friend of mine told me,

PHP Code:
for (keygetstringkeys("objectname.inv_")) 
Would work.

Edit: But if I did:

Here's what I'm doing:

PHP Code:
public function inventory()
{
  
invcontents = new TStaticVar();
  
invcontents.loadVars("levels/player_" player.account ".arc");
    for (
igetstringkeys("inv_"))
    {
      if (
== "item=")
      {
        
tokens getstringkeys("invcontents.inv_" i).substring(22).tokenize(",");
      }
      else if (
== "wep=")
      {
        
//stuff
      
}
      else if (
== "keyitem=")
      {
        
tokens getstringkeys("invcontents.inv_" i).substring(25).tokenize(",");
      }
      else if (
== "clothes=")
      {
        
tokens getstringkeys("invcontents.inv_" i).substring(25).tokenize(",");
      }
    }
  } 

Also, doing what you said and using, with, would I have to put "this.inv_" or could I just do "inv_".
"inv_" really just refers to temp.inv_, inv_ (global), or player.inv_. Not "this.inv_", your method works because you're making the variable global.

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:
        tokens invcontents.(@"inv_" i); 
Personally, I do not understand what you're trying to accomplish here.

Last edited by Novo; 04-10-2007 at 09:10 PM..
Reply With Quote
  #5  
Old 04-10-2007, 06:23 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
getDynamicVarNames()?
Reply With Quote
  #6  
Old 04-10-2007, 09:05 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
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:
  with (invcontents)
  {
    for (
igetstringkeys("this.inv_"))
    {
      if (
== "item=")
      {
        
tokens getstringkeys("invcontents.inv_" i)
      } 
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.

Last edited by killerogue; 04-10-2007 at 09:25 PM..
Reply With Quote
  #7  
Old 04-10-2007, 09:30 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by Chandler View Post
getDynamicVarNames()?
He's not trying to get the variable names hes trying to return whatever is after the 'inv_'
Reply With Quote
  #8  
Old 04-10-2007, 09:43 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Rapidwolve View Post
He's not trying to get the variable names hes trying to return whatever is after the 'inv_'
I'm trying to return whatever is after,

'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.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #9  
Old 04-10-2007, 09:50 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Hence like I said, everything after 'inv_', what your doing is right so far. Just use:
PHP Code:
with (findNPC("Database")){
  for (
temp.igetstringkeys("this.inv_"){
    echo(
temp.i); // Returns everything that starts with 'inv_'
  
}

Reply With Quote
  #10  
Old 04-10-2007, 09:53 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
*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.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #11  
Old 04-10-2007, 10:32 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Load the arrays first
PHP Code:
temp.playerData = new TStaticVar(); 
temp.playerData.loadVars("thistextfile.arc");
for (
temp.currentDatatemp.playerData.getDynamicVarNames())
  if (
temp.currentData.starts("inv"))
    
temp.foundData temp.currentData
Then you would like to load the temp.foundData, with whatever. I think that should work
Reply With Quote
  #12  
Old 04-10-2007, 10:36 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Chandler View Post
Load the arrays first
PHP Code:
temp.playerData = new TStaticVar(); 
temp.playerData.loadVars("thistextfile.arc");
for (
temp.currentDatatemp.playerData.getDynamicVarNames())
  if (
temp.currentData.starts("inv"))
    
temp.foundData temp.currentData
Then you would like to load the temp.foundData, with whatever. I think that should work

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.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #13  
Old 04-10-2007, 10:39 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
I'm not sure if that will work, your just overwriting the previous object. I would suggest 'item_id=Name, Icon'
Reply With Quote
  #14  
Old 04-10-2007, 10:43 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Rapidwolve View Post
I'm not sure if that will work, your just overwriting the previous object. I would suggest 'item_id=Name, Icon'
._. ......I suppose that would be easier, and more sensible, wouldn't it.
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.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #15  
Old 04-10-2007, 10:48 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by killerogue View Post
._. ......I suppose that would be easier, and more sensible, wouldn't it.
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?
I believe so, yes.
Reply With Quote
  #16  
Old 04-11-2007, 01:09 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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();
__________________
Reply With Quote
  #17  
Old 04-11-2007, 01:17 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
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 +2. The time now is 06:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.