Page 1 of 1
Increment a var?
Posted: Tue Sep 12, 2006 2:50 am
by Chilliden
Code: Select all
var dirt_portion := CInt(GetObjProperty(bowl, "DirtPortion"));
var targetted := Target(who);
SetObjProperty(bowl, "DirtPortion", dirt_portion);
if(targetted.objtype == Dirt)
dirt_portion := dirt_portion+1;
print(dirt_portion);
endif
Austin allready tryed to help, but it isn't working and i have no idea anymore. i just want to increment the var dirt_portion with one when they clicked the Dirt. PLs help
greetz
Posted: Tue Sep 12, 2006 3:11 am
by Bytehawk
Not sure, but I think if the cprop "DirtPortion" is not defined, dirt_portion will be an error instead of 0. Adding 1 to an error isn't 1, I guess
Try out this:
Code: Select all
var dirt_portion:= CInt (GetObjProperty (bowl, "DirtPortion"));
if (!dirt_portion)
dirt_portion:= 0;
endif
var targetted:= Target (who);
SetObjProperty (bowl, "DirtPortion", dirt_portion);
if (targetted.objtype == Dirt)
dirt_portion:= dirt_portion + 1;
print (dirt_portion);
endif
Re: Increment a var?
Posted: Tue Sep 12, 2006 3:25 am
by Austin
Chilliden wrote:Code: Select all
var dirt_portion := CInt(GetObjProperty(bowl, "DirtPortion"));
var targetted := Target(who);
SetObjProperty(bowl, "DirtPortion", dirt_portion);
if(targetted.objtype == Dirt)
dirt_portion := dirt_portion+1;
print(dirt_portion);
endif
Austin allready tryed to help, but it isn't working and i have no idea anymore. i just want to increment the var dirt_portion with one when they clicked the Dirt. PLs help
greetz
Read the comments for the code.. and I bet you'll find the mistake.
I didn't change anything, I just explained what the script is doing.
Code: Select all
// Reads the cprop "DirtPortion" as an integer.
// If it is an error (non existant), CInt() will force it to be 0.
var dirt_portion := CInt(GetObjProperty(bowl, "DirtPortion"));
// Store an object that was targetted or an error if nothing was.
var targetted := Target(who);
// Save the value of dirt_portion as a cprop named DirtPortion
SetObjProperty(bowl, "DirtPortion", dirt_portion);
// Check if what was targetted has an object type matching the value stored in variable 'Dirt'.
if( targetted.objtype == Dirt )
// Increment the value of dirt_portion by 1
// Only occurs if the target and Dirt match.`
dirt_portion := dirt_portion+1;
// Print hte value of dirt_portion to the console.
print(dirt_portion);
endif
// If there was no match, do nothing further?