Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Clearing Vars (https://forums.graalonline.com/forums/showthread.php?t=84916)

[email protected] 03-30-2009 07:32 PM

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]

Chompy 03-30-2009 07:52 PM

clientr. variables can't save objects when the player logs off (They're saved as strings in the accounts/*/* folder)

[email protected] 03-30-2009 07:58 PM

hmm- how would I resolve this? any ideas?

Chompy 03-30-2009 08:14 PM

Quote:

Originally Posted by [email protected] (Post 1479524)
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. :]

[email protected] 03-31-2009 06:12 PM

Ahh- that seems pretty pointless... I think I'll just stick to an array kind of format, thanks though!! =D

xXziroXx 03-31-2009 06:17 PM

Quote:

Originally Posted by [email protected] (Post 1479802)
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().

[email protected] 03-31-2009 06:37 PM

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?)

xXziroXx 03-31-2009 06:39 PM

Quote:

Originally Posted by [email protected] (Post 1479814)
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.

[email protected] 03-31-2009 06:54 PM

awesome- thank you :D


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);
    }
  }
}



All times are GMT +2. The time now is 04:58 PM.

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