Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Mudlib issue: (https://forums.graalonline.com/forums/showthread.php?t=72496)

Chandler 02-27-2007 09:10 PM

Mudlib issue:
 
Any reason why it isn't storing the array correctly? it should just save the "temp.newData" part as an array, however it refuses to do so! Any suggestions?
HTML Code:

function onCreated()
  {
  this.itemName = "Black Sword";
  this.itemDescription = "This great sword, once held by the almighty Chandler!";
  this.itemImage = "block.png";
  this.itemPrice = 300000;

  this.weaponName = "+Sword";
  this.causeEffect = {{"Poison", "Ice", "Fire"}, {100, 75, 75}}; 
 
  for (temp.itemData: getstringkeys("this."))
    temp.itemData.add(temp.itemData @"="@ makevar(@"this."@ temp.itemData));
 
  temp.newData = new TGraalVar();
  makevar(@"temp.newData.item-"@ this.itemName) = temp.itemData;
  temp.newData.savevars("itemData/newItem.arc", 0); 
 
  }


Riot 02-27-2007 09:32 PM

Quote:

Originally Posted by Chandler (Post 1282753)
Any reason why it isn't storing the array correctly? it should just save the "temp.newData" part as an array, however it refuses to do so! Any suggestions?
HTML Code:

function onCreated()
  {
  this.itemName = "Black Sword";
  this.itemDescription = "This great sword, once held by the almighty Chandler!";
  this.itemImage = "block.png";
  this.itemPrice = 300000;

  this.weaponName = "+Sword";
  this.causeEffect = {{"Poison", "Ice", "Fire"}, {100, 75, 75}}; 
 
  for (temp.itemData: getstringkeys("this."))
    temp.itemData.add(temp.itemData @"="@ makevar(@"this."@ temp.itemData));
 
  temp.newData = new TGraalVar();
  makevar(@"temp.newData.item-"@ this.itemName) = temp.itemData;
  temp.newData.savevars("itemData/newItem.arc", 0); 
 
  }


Right here:
HTML Code:

  for (temp.itemData: getstringkeys("this."))
    temp.itemData.add(temp.itemData @"="@ makevar(@"this."@ temp.itemData));

You might want to change this to something like:
HTML Code:

for (temp.data: getstringkeys("this."))
    temp.itemData.add(temp.data @"="@ makevar(@"this."@ temp.data));

Using the same name as the variable in the foreach and as the variable you're adding too will not work as expected.

Changing to that makes this file on the server for me:
HTML Code:

item-Black Sword="causeEffect=""Poison,Ice,Fire"",""100,75,75""","itemDescription=This great sword, once held by the almighty Chandler!",itemImage=block.png,"itemName=Black Sword",itemPrice=300000,weaponName=+Sword
joinedclasses=
scriptlogmissingfunctions=false
timeout=0


Admins 02-28-2007 12:19 AM

To save an array you normally need to use savelines(). I am not sure for what also those makevars are used (e.g. you should write
PHP Code:

temp.newData.("item-"this.itemName) = temp.itemData

). "new TGraalVar()" wont do anything either.

Chandler 02-28-2007 08:27 AM

Quote:

Originally Posted by Riot (Post 1282759)
Right here:
HTML Code:

  for (temp.itemData: getstringkeys("this."))
    temp.itemData.add(temp.itemData @"="@ makevar(@"this."@ temp.itemData));

You might want to change this to something like:
HTML Code:

for (temp.data: getstringkeys("this."))
    temp.itemData.add(temp.data @"="@ makevar(@"this."@ temp.data));

Using the same name as the variable in the foreach and as the variable you're adding too will not work as expected.

Changing to that makes this file on the server for me:
HTML Code:

item-Black Sword="causeEffect=""Poison,Ice,Fire"",""100,75,75""","itemDescription=This great sword, once held by the almighty Chandler!",itemImage=block.png,"itemName=Black Sword",itemPrice=300000,weaponName=+Sword
joinedclasses=
scriptlogmissingfunctions=false
timeout=0


Thank you!
I see now, thanks again! :p


Quote:

Originally Posted by Stefan (Post 1282802)
To save an array you normally need to use savelines(). I am not sure for what also those makevars are used (e.g. you should write
PHP Code:

temp.newData.("item-"this.itemName) = temp.itemData

). "new TGraalVar()" wont do anything either.

Oh, I see. I just see it being used, so I just use it. ^^

zokemon 02-28-2007 10:55 AM

Quote:

Originally Posted by Chandler (Post 1282972)
Oh, I see. I just see it being used, so I just use it. ^^

Are you sure you aren't thinking of new TStaticVar()?

Chandler 02-28-2007 07:06 PM

Quote:

Originally Posted by zokemon (Post 1282999)
Are you sure you aren't thinking of new TStaticVar()?

I don't think so, it could be though. :confused:

Inverness 03-01-2007 03:10 AM

TStaticVar is what you're thinking of.
TGraalVars are just the normal variables.

zokemon 03-01-2007 11:04 AM

TStaticVars let you use destroy() on them. ;)

Chandler 03-01-2007 08:58 PM

Quote:

Originally Posted by Inverness (Post 1283255)
TStaticVar is what you're thinking of.
TGraalVars are just the normal variables.

Yeah, I saw that when I viewed the page. Thank you two for clearing that up ^^

zokemon 03-03-2007 01:23 AM

Quote:

Originally Posted by Chandler (Post 1283485)
Yeah, I saw that when I viewed the page. Thank you two for clearing that up ^^

Not a problem :)

cbk1994 03-04-2007 05:44 AM

Quote:

Originally Posted by zokemon (Post 1283323)
TStaticVars let you use destroy() on them. ;)

Hours and hours of fun


All times are GMT +2. The time now is 11:30 PM.

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