Confusion about script in POS

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

Confusion about script in POS

Postby Xray » Mon Dec 15, 2014 8:23 pm

When I enter X and Y coords into pos using a local variable, Thyme will accept it if I enter it manually.
This is the script: { [_Xpos, 1.5] }

But if I enter exactly the same script with a keys.isDown command, then Thyme will reject it.
This is the script in onKey:
keys.isDown("Ctrl") ? {
pos = {
[_Xpos, 1.5]
}
} : {}

Also, if I use a numeric value (1.5) for the X-coord instead of using the local variable (_Xpos), then Thyme accepts the script!

What's going on here?

Mystery Script.phz
(3.33 KiB) Downloaded 65 times
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Confusion about script in POS

Postby Kilinich » Tue Dec 16, 2014 12:53 am

Problem is in the scope of executing code. To run it into box's scope add this:

Code: Select all
onKey := (e) => {
  keys.isDown("Ctrl") ?  {
    e.this -> {pos = {[_Xpos, 1.5]}}
  } : {}
}
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

Re: Confusion about script in POS

Postby Xray » Tue Dec 16, 2014 1:04 am

Ah... yes! I sometimes forget about the scope in which the code is executing. Your code does work exactly as desired. THANKS VERY MUCH! :clap:
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests