• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

If and while statement

C

Coolyo_Lars

Guest
Hello all,
I am currently working on a game for school. We just didn't have an explanation so I probably do something very stupid but I can't find a good solution anywhere. I'm making a platformer where a player has to jump to a door to get to the next level. I have two doors: the right door (this takes the player to the next level) and the wrong door (this takes the player back to the start of the room).
Software I use:
  • Gamemaker 8.1 lite

This is what I came up with:
if (keyboard_check (vk_space)) || place_meeting (x, y, RightDoor) {
room_goto_next ()
}

but now the player also goes to the next room without clicking the space bar. How can I best solve this?
Thank you for the help.
 

FrostyCat

Redemption Seeker
Use && here, not ||.

Did you read the Manual's entry on operators? It seems implausible that you'd be made to use a version of GM that old, yet not be given any instruction.
 
C

Coolyo_Lars

Guest
It seems implausible that you'd be made to use a version of GM that old, yet not be given any instruction.
We were allowed to work on it at school, but i wanted to also work on it at home and this is what i found on the web.

Because this is my final year og high school the teacher wanted to know how far we could come using tutorials and stuff like this.

Use && here, not ||.
But this seems to work so thx
 
C

Coolyo_Lars

Guest
I tought I was done. Now my Ladder doesnt work anymore. I tried a lot even typing it all over again. But it stopped working can you guys help me out?

this is the create event
Code:
grav = 1;
spd = 4;
jspd = 12;
hspd = 0;
vspd = 0;
onLadder = false

The ladder starts at line 48 this is the step event
Code:
if (place_meeting(x, y+1, Blok)){
    vspd = 0;
//naar boven     
    if (keyboard_check(vk_up)) {
    vspd = -jspd;
    }
} else {
    if (vspd < 10 ) {
    vspd += grav;
    
    }
}
//lets go to the right :)
if (keyboard_check(vk_right)) {
    hspd = spd;
}
// lets go to the left :)
if (keyboard_check(vk_left)) {
    hspd = -spd;
}
// check niet bewegen
if ((!keyboard_check(vk_right) && !keyboard_check(vk_left)) || (keyboard_check(vk_right) && keyboard_check(vk_left))){
    hspd = 0;
}
// horizontaal collisoin
if (place_meeting(x+hspd, y, Blok)){

    while (!place_meeting(x+sign(hspd), y, Blok)) {
        x+=sign(hspd);
        }
        hspd = 0;
}

//horizontaal bewegen

x+= hspd;

// verticaal collisoin
if (place_meeting(x, y+vspd, Blok)){
    while (!place_meeting(x, y+sign(vspd), Blok)) {
        y+=sign(vspd);
        }
        vspd = 0;
}
//beweeg verticaal
y += vspd;
//ladder
//nog op ladder?
if onLaddder == true && !place_meeting(x,y,oLadder)
    onLadder = false
//op de ladder om omhoog te gaan
if place_meeting(x,y,oLadder) && place_meeting(x,y+1,Blok)
    if keyboard_check(vk_up)
    onLadder = true
//op de ladder voor omlaag
if place_meeting(x,y+1,oLadder)
    if keyboard_check(vk_down)
    onLadder = true
//omhoogklimmen
if onLadder == true && keyboard_check(vk_up){
    y=y-3
    if !place_meeting(x,y,oLadder) {
    onLadder = false
    while(!place_meeting(x,y+1, oLadder))
    y+=1
    }
}
//naar beneden klimmen
if onLaddor == true && keyboard_check(vk_down){
var wallId, itsOK;
itsOK = false
wallId = instance_place(x,y+3,Blok)
if wallId<0
    y+=3
else {
    with wallId {
    itsOK = position_meeting(x,y,oLadder)
    }
    if itsOK == true
        y+=3
    else {
        while(!place_meeting(x,y,Blok))
        y+=1
    onLadder = false
    }
}
}

//verkeerde deur level reset
if (keyboard_check(vk_space)) && place_meeting(x,y, VerkeerdeDeur){
room_restart()
}

//volgende room
if (keyboard_check(vk_space)) && place_meeting(x,y, GoedeDeur){
room_goto_next()
}
 
Top