Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2009, 07:32 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Clearing Vars

I don't understand why these vars are not storing? They're being deleted once I reconnect

PHP Code:
function onCreated() {
  echo(
"Size:" SPC this.getCharacterList());
  
  for (
temp.0temp.5temp.i++) {
    
this.onCharacterCreate();
  }

  echo(
"Size:" SPC this.getCharacterList());
}

function 
onCharacterCreate() {
  
temp.charsize this.getCharacterList().size();
  if (
temp.charsize >= 15) return false;
  
  
temp.char.level 1;
  
temp.char.exp int(random(2099));
  
temp.char.gender randomstring("Male""Female");
  
temp.char.brave int(random(110));
  
temp.char.faith int(random(110));
  
temp.char.move int(random(510));

  
temp.stats = {"str""dex""con""int""wis""cha"};
  for (
temp.itemp.stats) {
    
temp.char.(@ i) = int(random(516));
  }
  
  
temp.char.hpmax int(random(75110));
  
temp.char.mpmax int(random(75110));

  
temp.list = {"Squire""Knight""Chemist"};
  
temp.class = randomstring(temp.list);
  
temp.char.classes temp.list;
  
temp.char.class = temp.class; 
  
temp.char.(@ temp.class).level 1;
  
temp.char.(@ temp.class).exp temp.char.exp;
  
temp.char.(@ temp.class).jp int(random(525));
  
  
temp.buffs = { {"dex""str""hpmax"}, //Squire
                 
{"str""con""hpmax"}, //Knight
                 
{"int""wis""mpmax"//Chemist
               
};
  for (
temp.itemp.buffs[temp.list.index(temp.class)]) {
    
temp.char.(@ i) += int(random(515));
  }
  
  
temp.char.hp temp.char.hpmax;
  
temp.char.mp temp.char.mpmax;
  
  
this.clientr.("char_" @ (temp.charsize 1)).copyfrom(temp.char);
  echo(
"Created" SPC temp.charsize 1);
}

function 
getCharacterList() {
  return 
getstringkeys("this.clientr.char_");

Any suggestions? thanks

[Don't comment on the this.clientr/clientr, that isn't the problem]
Reply With Quote
  #2  
Old 03-30-2009, 07:52 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
clientr. variables can't save objects when the player logs off (They're saved as strings in the accounts/*/* folder)
__________________
Reply With Quote
  #3  
Old 03-30-2009, 07:58 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
hmm- how would I resolve this? any ideas?
Reply With Quote
  #4  
Old 03-30-2009, 08:14 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by [email protected] View Post
hmm- how would I resolve this? any ideas?
Make the object into an array before they logoff, then turn it into an object again when they logon. :]
__________________
Reply With Quote
  #5  
Old 03-31-2009, 06:12 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Ahh- that seems pretty pointless... I think I'll just stick to an array kind of format, thanks though!! =D
Reply With Quote
  #6  
Old 03-31-2009, 06:17 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by [email protected] View Post
Ahh- that seems pretty pointless... I think I'll just stick to an array kind of format, thanks though!! =D
When I was working on GK's quest system, I was storing information in a clientr. TStaticVar object, and upon onPlayerLogout(), I converted it to several strings (one for each quest), and then reloaded it into the object (and removing the strings) upon onPlayerLogin().
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 03-31-2009, 06:37 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Works a charm =D
Thanks

One question... I was thinking of storing the information as client. vars, but thats quite insecure, however on login it will be converted to clientr, is that a bad idea or? (as the player won't have time to edit anything on login or whilst they're logging out, right?)
Reply With Quote
  #8  
Old 03-31-2009, 06:39 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by [email protected] View Post
Works a charm =D
Thanks

One question... I was thinking of storing the information as client. vars, but thats quite insecure, however on login it will be converted to clientr, is that a bad idea or? (as the player won't have time to edit anything on login or whilst they're logging out, right?)
Just go with clientr. vars from the start, and save yourself a lot of trouble.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #9  
Old 03-31-2009, 06:54 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
awesome- thank you


Edit:

Something like this you mean, right?
HTML Code:
function onLoadCharacters() {
  for (temp.i = 1; temp.i < clientr.cha_size; temp.i++) {
    temp.list = getstringkeys("clientr.cha_" @ i @ "_");
    for (temp.var: temp.list) {
      clientr.("char_" @ i).(@ var) = clientr.("cha_" @ i @ "_" @ temp.var);
      clientr.("cha_" @ i @ "_" @ temp.var) = null;
    }
  }
}
  
function onSaveCharacters() {
  temp.list = getstringkeys("clientr.char_");
  clientr.cha_size = (temp.list.size() + 1);
  
  for (temp.i: temp.list) {
    temp.data.copyfrom(clientr.("char_" @ i));
    for (temp.var: temp.data.getdynamicvarnames()) {
      clientr.("cha_" @ i @ "_" @ temp.var) = temp.data.(@ temp.var);
    }
  }
}

Last edited by [email protected]; 03-31-2009 at 07:59 PM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:42 AM.


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