Game Development Community

Why is this code executing twice?

by Steve Howson · in Torque Game Engine · 09/08/2005 (7:22 pm) · 4 replies

Hi all.
Using some help I got in the Discussion forum, I'm playing around with the scripts to help me learn Torque (just recently purchased it).

I have the following code in my default.bind.cs:
function build(%val)
{
	echo("Build function activated.");
}

moveMap.bind( keyboard, b, build );

It's inserted in where the other move keys are (a, d, w, s, etc...).

When i load it up and hit the b key, it displays 'Build function activated.' in the console, but displays it one line right under the other.

I don't yet know enough about Torque to figure out why it's executing twice, so if someone could help shed some light on this I'd appreciate it! :)

Thanks a lot!
Steve

#1
09/08/2005 (7:28 pm)
If you echoed %val, you'd see a 1 and then a 0. That's the make/break. Try this code instead:
function build(%val)
{
   if (%val)
      echo("Build function activated.");
}

moveMap.bind(keyboard, b, build);

That should fix you right up. If instead you want it to trigger on the break, change it to "if (!%val)"

- Brett
#2
09/08/2005 (7:37 pm)
Ahh, ok.
So it's basically executing once when the function is "entered" and once when it's "exited"?

Thanks for the info!
Steve
#3
09/08/2005 (7:58 pm)
No, it's executing once when the key is pressed and once when it's released.

1 = pressed, 0 = released
#4
09/08/2005 (9:33 pm)
Cool deal.

Thanks for the info!
Steve