Script crashing blockland

Author Topic: Script crashing blockland  (Read 3385 times)

in ServerCMDCcyes

echo("Did we reach here? Or did it crash?");
   %eval = "cityRPGData.getData(" @ %target.getBlid() @ ").value" @ %client.CropSell @ " -= " @ %client.CropSellAmnt @ ";";
   echo(%eval);
   eval(%eval);


"Did we reach here? Or did it crash?" is the last thing to echo before blockland crashes.
I was using eval as a way to avoid stacks of ugly ifs

cityRPGData.getData(%target.getBlid()).value[%client.CropSell] -= %client.CropSellAmnt;

Yeah there's very few cases where you need to, or even want to, use eval
You seem to be doing here as a way to not use arrays, which is strange because with Torque's stuffty array implementation and $array[1] being the same as $array1, pretty much their only purpose is to prevent you from needing to do exactly what you did.

I'm not familiar with CityRPG's code at all, but that seems a very strange way to retrieve the data (client has already been given through the getData function, why is it needed again in the array index? Are you sure the index shouldn't just be "cropSell" ?), so you may want to look into it further.

Why are you doing
(" @ %target.getBlid() @ ")
instead of
(%target.getBlid())

You don't need to create an empty string just to put variables into it, just putting them in works fine.

cityRPGData.getData(%target.getBlid()).value[%client.CropSell] -= %client.CropSellAmnt;
That would actually work a whole lot better than what I did.

Why are you doing
(" @ %target.getBlid() @ ")
instead of
(%target.getBlid())

You don't need to create an empty string just to put variables into it, just putting them in works fine.
6 of one half a dozen of the other, they both have the same outcome. Unless one is more efficient that is.

6 of one half a dozen of the other, they both have the same outcome. Unless one is more efficient that is.
Eval forces the game to compile the entered code into TS bytecode, which is very costly performance-wise.

Eval forces the game to compile the entered code into TS bytecode, which is very costly performance-wise.
This, plus the way you did it is a forgetton less readable than arrays

I didnt know that $Array1 is equal to $Array[1] until now. That will be VERY helpful.

I didnt know that $Array1 is equal to $Array[1] until now. That will be VERY helpful.
Also, you can use a for loop to get all of them.
Let's say you have all the way to $array[8]:

for(%i = 0; %i < 9; %i++)
    echo($Array[%i]);

I didnt know that $Array1 is equal to $Array[1] until now. That will be VERY helpful.
For multidimensional arrays:
$array[1,2] would be the same as $array1_2

It does have it's niche uses (Not too long ago, using the GUI editor, I gave a series of objects names in the pattern of Name<A>_<Y> so I could iterate through them in code) but for most uses you'll just be using the array format to access it

Same as $ArrayArray1 with $Array["Array1"]

You can also do $Array["Array 1"] which will be the same as $ArrayArray 1. Make sure you don't allow spaces or you won't be able to execute saved or exported variables.

You can also do $Array["Array 1"] which will be the same as $ArrayArray_1. Make sure you don't allow spaces or you won't be able to execute saved or exported variables.
Shouldn't there be a _ ?

No. Torque doesn't convert spaces to underscores with name insertion.

You should use an underscore rather than a space, because if you export and then exec it with a space, it will give a syntax error.

« Last Edit: July 13, 2014, 12:30:32 PM by Headcrab Zombie »