Press specific key to change an object's collisionGroup

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

Press specific key to change an object's collisionGroup

Postby AN9K » Fri Feb 17, 2017 12:32 pm

Is this code correct?

Code: Select all
OnKey=(e)=>{
collisionGroup = (Keys.bind == 'v') ? 5 : 4
}
AN9K
 
Posts: 5
Joined: Tue Jun 30, 2015 12:14 am

Re: Press specific key to change an object's collisionGroup

Postby The Linkage » Wed Feb 22, 2017 11:42 pm

Not really...

The code is much simpler actually. You have to use keys.isDown("key"), keys.bind is only to bind keys to the GUI
First of all: If you write on onKey, your script will run more efficiently (no lag while not pressing the key) but when you release the key the script will not update (this means, you're saying: If you're pressing this key, change collideSet, if you release, change it again - but when you release it the script will not change the collideSet as it is not active). SO what you have to do is put it on the collideSet property itself (or on postStep or update if you want, but the script is shorter on collideSet)
So it will be like this:

Code: Select all
collideSet = {
keys.isDown("v") ? 5:4
}


That will make the object collision layer A and C when you press V, and only C when you release it

If for some weird reason you wanted to write that down on postStep or update, then do this:

Code: Select all
postStep(or update, same) = (e)=>{
collideSet = (keys.isDown("v") ? 5:4)
}


The particular thing about this code is that you'll be able to see which collideSet is active while the scene is running, from the script menu itself

If you need more help just ask. hope you don't do algicosathlon, whoever you are...
The Linkage
 
Posts: 57
Joined: Fri Aug 05, 2011 5:40 pm
Location: Escobar, Argentina

Re: Press specific key to change an object's collisionGroup

Postby Kilinich » Thu Feb 23, 2017 10:03 am

AN9K wrote:Is this code correct?

Code: Select all
OnKey=(e)=>{
collisionGroup = (Keys.bind == 'v') ? 5 : 4
}


No.
keys.bind is interface customization for your PC only. Than bindings not saved with scene.
Use onKey or keys.isDown instead.

http://www.algodoo.com/forum/viewtopic.php?f=13&t=10580&start=0
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 9 guests