These forums are CLOSED. Please visit the new forums HERE
How to do this |
|
Leb Raven
Registered User
Join date: 7 Jun 2005
Posts: 6
|
06-07-2005 08:06
Hi, I'm new to scripting and I have a question... Is there any way to change a variable? Say I have a value that will, over time increase. How can I do this? Say I want a number to go up when the object recieves a command, what should I do?
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-07-2005 08:37
Declare the variable, maybe as a global (above the default state)
e.g. CODE
then either counter++ or ++counter will do it. Receives a command? Well it needs to go in an event, you just put it in there. Say you want it to receive a command by touch it would go CODE
|
Leb Raven
Registered User
Join date: 7 Jun 2005
Posts: 6
|
06-07-2005 10:14
From the Wiki "Note: a default value is specified, and it should be expected by the programmer that this value will not change at runtime. " (In reference to variables).
Is there any way for it to change at runtime, and store it? By perhaps writing to a notecard? The value I need to change in runtime, and still be different upon the next rez. How is this possible? |
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-07-2005 10:22
Test it to be sure, but I'm pretty sure that as long as you don't set a default value it won't change on rez. Something like this should do:
CODE
If it does clear the counter each time the best bet, for something like that, is to store it in the item description. There is no sure way to store large amounts of data in SL yet, but a number you can hide here or in other ways if you need people not to be able to see the number with a mouseover - llSetAlpha() or llSetScale() or similar, then use the corresponding llGet () functions to read it back. |
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
|
06-07-2005 10:31
Probably simplest and most reliable would be...
CODE llSetObjectDesc((string)my_counter); ...you could hide it on a linked child prim if you were feeling fancy. /esc _____________________
http://slurl.com/secondlife/Together
|
Leb Raven
Registered User
Join date: 7 Jun 2005
Posts: 6
|
06-07-2005 10:53
Could I do counter-- to subtract from it?
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-07-2005 10:57
yup
|
Leb Raven
Registered User
Join date: 7 Jun 2005
Posts: 6
|
06-07-2005 11:05
Hmm... And what if I wanted to subtract an amount higher than 1, and wanted a starting number other than 0?
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-07-2005 11:24
lol.
Try http://secondlife.com/badgeo/wakka.php?wakka=operators but you assign using =, e.g. integer counter = 66; counter +=5 or counter = counter + 5 will both do. counter -=23 or counter = counter - 23 similarly. float counter = 2.1728 counter = counter * PI will work too... |
Leb Raven
Registered User
Join date: 7 Jun 2005
Posts: 6
|
06-07-2005 11:51
I want to be able to do counter-- when the if llListen(50, "", "","bang"
![]() |
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-07-2005 16:48
CODE
Can I suggest the scripting library and Crash Course might be good places to start you off, see how others have done these things... |
Zindorf Yossarian
Master of Disaster
![]() Join date: 9 Mar 2004
Posts: 160
|
06-08-2005 06:22
I'm glad Eloise finally gave the big picture there. I was worried that Leb would start using counter--; counter--; counter--; counter--; to subtract 4. And that would be uncool. C'mon people, no half-assed explanations. To add a bit,
counter += 5 is the same as saying counter = counter + 5 That's good for incrementing or decrementing by more than 1. _____________________
Badass Ninja Penguin: Killing stuff it doesn't like since sometime in May 2004.
|