It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
Hi,

I'm currently trying to redo a game I made a long time ago in Game Maker, using a simple platform engine I made more recently, but I'm having a bit of trouble with creating elevators.

Basically, I want it to check if the player is a certain distance from the elevator, and if the player is within that distance then it will check to see if the action key is being pressed, then, if it is then it will check to see what position it is in via a variable, and if it is in position 1 then it will go down, and 2 it will go up. I know how to do most of that, I am just having trouble with one section - here is my code:

if distance_to_object(obj_player)<10;
{
if keyboard_check_pressed(vk_control)if variable elev_position=1
}
then vspeed = 2

else

I still got to add the variable check, but it keeps telling me that then is an 'Unexpected symbol in expression"

Is there something wrong with my formatting, or the code itself?

Thanks

sv
This question / problem has been solved by SCPMimage
It's been a long time since I used GML. I removed the semi-colon from the first if statement, wrapped the inner most if statement in brackets, changed the elev_position if statement to using the equality test == as opposed to the assignment operator = for clarity's sake, and I put the then statement inside the brackets, and I added the else if statement below:
if distance_to_object(obj_player)<10
{
if keyboard_check_pressed(vk_control)
{
if variable elev_position == 1 then vspeed = 2
else if variable elev_position == 2 then vspeed = -2
}
}

Something still feels off about it, and I wish I had GM installed so I could test it but I think that's about the gist of what you intend to do?
Edit: dang, spacing doesn't work well on the forum posts.
Post edited September 11, 2012 by SCPM
avatar
SCPM: if variable elev_position == 1 then vspeed = 2
At the two equals signs it says Assignment operator expected... from just reading your code I think what you wrote will be spot on, but do you know how to fix the error I said above?
avatar
SCPM: if variable elev_position == 1 then vspeed = 2
avatar
sloganvirst: At the two equals signs it says Assignment operator expected... from just reading your code I think what you wrote will be spot on, but do you know how to fix the error I said above?
Could you post which line the error is pointing to, plus a few lines above it, as something earlier in the code could cause this. And did you delete the semi-colon from the part you quoted?
avatar
sloganvirst: At the two equals signs it says Assignment operator expected... from just reading your code I think what you wrote will be spot on, but do you know how to fix the error I said above?
avatar
SCPM: Could you post which line the error is pointing to, plus a few lines above it, as something earlier in the code could cause this. And did you delete the semi-colon from the part you quoted?
I copied that bit of yours, to see if it worked. Here it is:

if distance_to_object(obj_player)<10
{
if keyboard_check_pressed(vk_control)
{
if variable elev_position == 1 then vspeed = 2

else if variable elev_position == 2 then vspeed = -2
}
}
The bit in bold is the bit with the error, it says at Line 5, position 28, so just in between the equals signs.

Nevermind dude, I forgot that you didn't have to declare it was a variable in GML, changing "if variable ???" to "if ???" worked! Thanks a lot for your code though bro, it fixed my original error
Post edited September 11, 2012 by sloganvirst
avatar
SCPM: Could you post which line the error is pointing to, plus a few lines above it, as something earlier in the code could cause this. And did you delete the semi-colon from the part you quoted?
avatar
sloganvirst: I copied that bit of yours, to see if it worked. Here it is:

if distance_to_object(obj_player)<10
{
if keyboard_check_pressed(vk_control)
{
if variable elev_position == 1 then vspeed = 2

else if variable elev_position == 2 then vspeed = -2
}
}
The bit in bold is the bit with the error, it says at Line 5, position 28, so just in between the equals signs.

Nevermind dude, I forgot that you didn't have to declare it was a variable in GML, changing "if variable ???" to "if ???" worked! Thanks a lot for your code though bro, it fixed my original error
That's right, I completely forgot about that part. Well, I'm glad it works now. :)