Increment a var?

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Chilliden

Increment a var?

Post 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
Bytehawk
Apprentice Poster
Posts: 56
Joined: Fri Feb 03, 2006 2:25 am

Post 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
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: Increment a var?

Post 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?
Post Reply