onCollide: Check variable?

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

onCollide: Check variable?

Postby tgp1994 » Thu Jul 22, 2010 11:15 pm

Hi everyone. I'm very new to Thyme scripting, (I kind of wish it was LUA, but w/e) and I'm trying to create a function that will check the variable of the object that hit it (the variable is called "name") to a string. Does anyone know what this would look like?

I.E. What I'd want it to look like is onCollide = (e)=>(other.name = "Box") ? print("A box.") : print("Not a box.")

Thanks in advance.
tgp1994
 
Posts: 23
Joined: Fri Sep 04, 2009 4:09 pm

Re: onCollide: Check variable?

Postby daniels220 » Fri Jul 23, 2010 12:36 am

That code should almost work. You need == for checking equality, and e.other.name instead of simply other.name. (args)=>{body} is a function literal in Thyme, and e is the event object. If you've ever done any JS or Flash programming, it's exactly like that, except Thyme is even more reliant on the event object. Also, print() isn't a function in Thyme—it's console.dump or something. Check the commands/vars thread, that's where I found it when I needed it.
daniels220
 
Posts: 95
Joined: Mon Aug 31, 2009 11:30 pm

Re: onCollide: Check variable?

Postby tgp1994 » Fri Jul 23, 2010 12:57 am

Actually, print has been working just fine for me. So e.other.name? That makes sense, although I originally thought that the other object was provided to the function outside of e. Has it ever been considered to create an entire Thyme documentation on the wiki, like all functions, and examples? I know there are two forum topics for that, but in the wiki would be better. I'd gladly contribute.
tgp1994
 
Posts: 23
Joined: Fri Sep 04, 2009 4:09 pm

Re: onCollide: Check variable?

Postby daniels220 » Fri Jul 23, 2010 6:21 pm

Oh, maybe it does work.

Creating Thyme docs...there's the commands/vars thread. It could be copied pretty much verbatim into wiki pages. You could ask if it'd be okay to do that. It would certainly be easier to add to in that format.
daniels220
 
Posts: 95
Joined: Mon Aug 31, 2009 11:30 pm

Re: onCollide: Check variable?

Postby tgp1994 » Fri Jul 23, 2010 7:49 pm

Definitely, although I was thinking we should make separate pages for different functions/classes.
tgp1994
 
Posts: 23
Joined: Fri Sep 04, 2009 4:09 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests