if statement

  1. MartinK12

    GML Checking logical statements vs calculating variables – performance wise?

    I heard somewhere that logical statements like if take more time to process then calculating variables so I wonder if I should leave all variable calculations alone or put them inside if statements. For some basic example in step event - is the first way faster then the second? Is it even worth...
  2. S

    Trouble getting out of loop when creating instances on my Enemies

    So I am trying to make a multi layered shield (randomly set) anywhere from 1 to 3 objects on top of my enemy and each shield chooses a different frame depending on what layer it is. theres 3 different color shields and I want it to choose 1 color per layer but for some reason it continues the...
  3. 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...
  4. 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 =...
  5. 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...
  6. 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?
  7. 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...
  8. 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...
  9. 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?
  10. 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...
  11. 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...
  12. L

    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)) {...
  13. 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?
  14. 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...
  15. 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) {...
  16. 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] =...
  17. 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){...
  18. 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 ///...
  19. 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 }
  20. 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...