Bind max speed to a variable?

Get help using Construct 2

Post » Sat Feb 09, 2013 2:53 pm

So... I'm completely new to this software. Came here from Gamemaker to see what was going on over here

I got a sprite with the 8Direction behavior. What I want to do is bind the Max Speed with an Instance Variable (Since I can not find a subtract/add event linked with Max Speed).
Say it starts at 200. When I click ctrl it subtracts 100. Shift adds 100.
So I don't have to hold down a key to change the speed. I tab it.

Now I can imagine Gamemaker isn't too popular over here?
But just to show what I mean in GML:
I got a variable called playerSpeed and code looking like this:

if keyboard_check_pressed(vk_shift)
playerSpeed += 100

if keyboard_check_pressed(vk_control)
playerSpeed -= 100

if (playerSpeed > 300)
    playerSpeed = 300

if (playerSpeed < 100)
    playerSpeed = 100
Posts: 2
Reputation: 554

Post » Sat Feb 09, 2013 3:19 pm

It's the same kind of logic here, events replace if/else statements but functionally they're the same.


[System] Every Tick
[Event]     On key pressed (LShift)
[Action]       playerSpeed = playerSpeed + 100

If you want it incremental you just:

[System] Every Tick
[Event]     On key held (LShift)
[Action]       playerSpeed = playerSpeed + 100

And so on...

If you haven't already, you might wanna go through a tutorial or two to get a feel for the C2 "syntax". It's real easy, but the clickiness and some of the C2 terms can feel a bit alien at first.
Posts: 542
Reputation: 7,617

Post » Sat Feb 09, 2013 4:05 pm

ErekT is right you can easily do this kind of logic with events.
However, In this case you should be able to create these actions without the every tick event by adding a condition or sub-event that compares the players maxspeed to another value (in you example 100 & 300).

And just to clarify on accessing an objects properties,

I not sure how the gamemaker language compares but in C2 to change an objects properties you sometimes have to dig into it a bit. For example speed is part of a behavior, in this case 8direction movement, so you have to access the behavior too. To get/alter the object's speed property you would need...


then you can add / subtract from it using the set maxspeed action
action: set object's maxspeed to objectname.8Direction.MaxSpeed + 100
Posts: 12
Reputation: 1,049

Post » Sat Feb 09, 2013 4:27 pm

It can be really simple for the keypress checking.

Add an instance variable for the max speed and do something like:

when Throttle key is pressed condition on the same block with a maxSpeed>100 . Then the action set to add 1 to the max speed variable.

That is so that 100 is the cap, and they can not hold the throttle key longer. then set a decelerate key to subtract from the maxspeed variable or have it reset on a throttle key up condition.

It would probably take less processing power to just cap the throttle rather than trying to get the current speed of something, and then capping it.

I can see when getting the current speed would be needed, especially if the car collides with things that will slow it down.

The above example would be better with something like a space ship, but with a little complexity you can probably make it work for you.jojoe2013-02-09 16:36:01
Posts: 767
Reputation: 5,985

Post » Sat Feb 09, 2013 5:19 pm

Keypress itself is an event so you don't have to do the every tick check. That just adds extra overhead. You should use every tick as little as possible.
Posts: 1,833
Reputation: 14,583

Return to How do I....?

Who is online

Users browsing this forum: Evil Snowman0, R0J0hound and 7 guests