if statement

  1. el_Bro

    GML var inside the if loop block

    Hi, I know we can omit parentheses: var x = 5; if(x) show_debug_message("x = 5"); var y = 1; show_debug_message("y = 1"); output: // x = 5 // y = 1 Is variable 'y' inside or outside the loop? How to put it in if statement that doesn't have parentheses? And is this that case when I have to write...
  2. William Garrison

    GMS 2 if Toggle

    Why doesn't this work? var toggle = false; if keyboard_check_pressed(ord("1")) && (!toggle) { image_index = 1; toggle = true; } if keyboard_check_pressed(ord("1")) && (toggle) { image_index = 0; toggle =...
  3. D1Project

    Drag And Drop Drag and Drop if [...] or [...]

    Hello, Using Drag and Drop, is there a way to do if [...] or [...] ? The only workaround I found is to use an "If Expression" and put the whole expression in. For example, if I have a boss with 4 phases, but I want him to execute the same action on phase 2 and 4. In GML, we would put "if phase...
  4. FacesOfMu

    GMS 2 Variable assignment and if statement in one line SOLVED! conditional or ternary operations

    There's a way to do: var foo = (if x then y; else z); But I can't for the life of me find out the name of this kind of statement to look up the syntax. Can anyone help?
  5. Z

    GML image_angle checks randomly stop working mid-game

    Hi, I am currently working on my top down GTA 1 style game, and I have run into an issue. When the player is wanted by police, every 16 - 30 seconds, I want the dispatcher to announce the player's direction. ///Direction Update ///Wanted by police and driving a car if(wanted == true and...
  6. E.M.I

    GMS 2 How to change the value of all objects inside an array

    Hey GameMaker community! So I'm trying to make a basic script that assures that shadows will always appear in front of the player but always appear behind the object they're the shadow of. For this I'm making code that, when the shadow collides with the player, changes the depth value of the...
  7. William Garrison

    GML Inline IF Statement

    Okay simple questions for your Wednesday Morning...I come from JS and I know how to write up an inline IF statement there but doesn't seem to quite apply to GML. JS would be if (A) ? B : C GML Inline IF?
  8. Jochum

    GML Problem with step event and point_in_rectangle

    Hi guys, I created this piece of code, for some reason it's not working. I have the variables stored in the create page and as check I created a rectangle with the same positions as I'm checking in the step event (same variables). The rectangle is drawn on the right place but for some reason...
  9. M

    GML Help with FOR LOOPS

    Hi All, I am making a game. The player has no hp at the start, but with each 3 hearts that he gathers, one hp is added. I tried with if statement, with do... until, and I tried a for loop, but nothing seems to work. It either adds just one hp and stops there, or keeps adding infinite number of...
  10. LunarIceCream

    GML [Solved] Horizontal collision problem with Enemy Object

    So I was making a platformer using a tutorial from Shaun Spalding, and it was a little outdated but overall working fine, until I got to this specific line of code with the oEnemy object in the step event. if (place_meeting(x+hsp,y,oWall)) { while (!place_meeting(x+sign(hsp),y,oWall)) {...
  11. Dr_Nomz

    GML using brackets in IF statements? (does it matter?)

    So this is how most of my IF statements look: if (keyboard_check(vk_shift) == true) But, does it NEED brackets? And if so, why? What's the difference with or without them? Should I always use brackets?
  12. Jmarlin3

    Issues with instances and if statements

    So the player object is supposed to cross over a floor object, with the floor object switching to a red floor object. If the player object is not touching the red floor object anymore, the red floor object dissapears and turns into a wall object, meaning they can't go back.the Here's the code...
  13. N

    Legacy GM When this, skip the next ?

    Hi. I have a quick question, this is my code: if (!place_meeting(x+sign(hsp),y-8,par_ground) && !place_meeting(x+sign(hsp),y-8,obj_pipe)) { with (obj_oneway) { if (place_meeting(x-sign(other.hsp),y+8,other)) { if !(bbox_top > other.bbox_bottom) {...
  14. D

    GMS 2 If statement not working

    I've been trying to make a spawner in a game and the code wont spawn anything. in the step event if(obj_stats.level < 5 and spawn == true) { alarm[0] = 30 spawn = false alarm[2] = 32 } else if(obj_stats.level < 10 and spawn == true){ alarm[0] = room_speed * 7.5 alarm[1] =...
  15. D

    GML If Statement Not Working (solved)

    My if statement wont work. The object is created even though i did not press the "z" button or the timer is not done yet. All it looks for seems to be only the facing up (north). if(keyboard_check("z") and sprite_index == spr_playerN and sword == true){...
  16. Patrick Johnson

    GMS2 While and If statements Error Malformed

    I'm having an issue with the "while" and "if" statement in my code. I run the compiler but it says that the function is malformed, regardless of whether or not I use "while" or "if". It works fine in GMS 1.4 but not GMS2. /// Code in the game > o_enemy > create event ///...
  17. S

    GMS 2 Using OR to compare different values

    Just a quick question: will this work? var a = 1; var b = 1; var c = 2; if a == (b || c) { // execute code } Or do I have to write it out like this: var a = 1; var b = 1; var c = 2; if (a == b) || (a == c) { // execute code }
  18. N

    If statement && ||

    Hi all! I am making a CPU for a game. It's a 2D shooting game. But that doesn't matter. To get straight to the point, let's take a look at my code. Me :: obj_player_red Bot :: obj_bot ///Step Event obj_bot if keyboard_check_pressed(vk_space){ // If you pressed...
  19. R

    Legacy GM If statement runs twice regardless of logic

    Hello! I want to try out something, but not working: i made a ds_list called _stations I made a variable containing the next point id _nextstation I wrote the next, but the code behaves on a strange way: itruns twice, and the variable _nextstation increment two times but the statement after...
  20. Fixer90

    Legacy GM If and or, or if and or? (SOLVED)

    Let's say I want to make an if statement with lots of &&s (ands) and ||s (ors). I'll use the following code as an example: CREATE EVENT variable_a = false; variable_b = false; variable_c = false; STEP EVENT if(variable_a == true) && (variable_b == true) || (variable c == true) { //stuff...