Constantly updated Variable

About advanced scenes, and the Thyme scripting language used in Algodoo.

Constantly updated Variable

Postby niffirg1 » Fri Dec 11, 2009 12:59 am

So I was running a scene and i set a variable (Lets say scene.my.varex) equal to lets say 100 and i type in the console
Code: Select all
scene.my.varex = scene.my.varex * 1.5
so i do that and now it is at 150 then i type in the console
Code: Select all
scene.my.varex = scene.my.varex * 0.9
So then thinking it would spit out 135 it spits out 90. So then i realized the variable is staying at 100 instead of being updated to 150. Then i thought of an argument taking function to constantly update the scene.my.varex but could not figure it out. Any Help please?
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Constantly updated Variable

Postby KarateBrot » Fri Dec 11, 2009 1:33 am

{ } - brackets tell algodoo that the code between it is a variable. Otherwise it will be treaten like a constant.

That's why you always have to put the code in the scripting menu between { } - brackets to let it refresh all the time and not only once.


[Edit]
Oh, wait. I didn't understand your problem I think.
I did what you described but it gave me the value of 135. It works for me. Make a new scene and test it again.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Constantly updated Variable

Postby niffirg1 » Fri Dec 11, 2009 4:14 am

Let me explain more clearly ok so i set a variable to 100 and it is being multiplied constantly by a number between -10 and 10. So when the number it 5 then the 100 is turned to a 500 because the variable is being multiplied by that number then the number changes to 2 the variable changes to 200 and i expected it to turn to 100000. Is that a better explanation
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Constantly updated Variable

Postby KarateBrot » Fri Dec 11, 2009 4:31 am

niffirg1 wrote:Let me explain more clearly ok so i set a variable to 100 and it is being multiplied constantly by a number between -10 and 10. So when the number it 5 then the 100 is turned to a 500 because the variable is being multiplied by that number then the number changes to 2 the variable changes to 200 and i expected it to turn to 100000. Is that a better explanation


What do you expect to turn to 100,000? The variable or something else? Because if you just multiply the variable by 2 it would be 1,000 and not 100,000. That's what's unclear. Sorry that I'm aksing too much but I need to know exactly what needs to be calculated :D
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Constantly updated Variable

Postby niffirg1 » Fri Dec 11, 2009 4:36 am

The variable and i multiplied it by 200 not 2
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Constantly updated Variable

Postby KarateBrot » Fri Dec 11, 2009 4:58 am

I still can't get what you want to say. It doesn't make sense to me that in the second step the number is changing to 2, then the variable changing to 200 and then to 100,000.
I'll just post an algorithm. Tell me if it's correct or what's wrong.

  • variable = 100

    loop:
  • number = random(-10,10)
  • variable = variable * number
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Constantly updated Variable

Postby Kilinich » Fri Dec 11, 2009 5:37 am

niffirg1 wrote:So I was running a scene and i set a variable (Lets say scene.my.varex) equal to lets say 100 and i type in the console
Code: Select all
scene.my.varex = scene.my.varex * 1.5
so i do that and now it is at 150 then i type in the console
Code: Select all
scene.my.varex = scene.my.varex * 0.9
So then thinking it would spit out 135 it spits out 90. So then i realized the variable is staying at 100 instead of being updated to 150. Then i thought of an argument taking function to constantly update the scene.my.varex but could not figure it out. Any Help please?

Just use this code
Code: Select all
scene.my.varex = 0.9 * scene.my.varex
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests