It is currently Fri Nov 21, 2008 9:40 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Increment a var?
PostPosted: Tue Sep 12, 2006 2:50 am 
Code:
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


Top
  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 3:11 am 
Offline
User avatar

Joined: Fri Feb 03, 2006 2:25 am
Posts: 56
Location: Germany, Franconia
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:
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

_________________
Image


Top
 Profile  
 
 Post subject: Re: Increment a var?
PostPosted: Tue Sep 12, 2006 3:25 am 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 2:30 am
Posts: 428
Location: San Diego, California
Chilliden wrote:
Code:
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:
// 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?

_________________
-Austin


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl