switch case

  1. Diegoegoeog

    SOLVED What code line is the best?

    I have these 2 code lines for act in sprite anim. I prefer use switch case, but in comparison with if else, seems more slow or something. Switch Case //Sprite Animation var spriteAnim = abs(sign(velocity_[vector2_x])); switch(spriteAnim) { case 0: sprite_index =...
  2. nuclear_shmatt

    switch statement case 2 code won't run

    So, everything works, up until the "switch(i) case 2:" where it just doesn't run even though in the debugger, the 'i' variable does reach 2. if(!menu_check) { switch(menu_type) { case MENU_BAR.NORMAL: for(var i = 0; i < menu_amount; i++) {...
  3. NovemberTender

    SOLVED switch statement loop even with break;

    if ((menuability_commited != -1) and (global.menuability == true)) switch (menuability_commited) { case 4: { instance_create_layer(oPlayer.x, oPlayer.y, "Held_Tools",oFireorb); break; } case 3: {...
  4. Misael644

    SOLVED Event collision problems involving multiple instances.

    Hello again! I'm here because I'm having problems with my game's collision event. Basically, I'm trying to simulate a starfield that works like this: I have an object called "obj_star", in the game, it is spawned by "obj_starcreator", which spawns a star in a random place on the screen. And so...
  5. Evan Kinsler

    GMS 2.3+ (State Machine) Am I in the right direction with this?

    So today I tried to make a navigatable menu using only knowledge I have gathered from state machines and enums. At the moment nothing shows up. This is what I have inserted into the room... just these 4 things. And here is the code I have for a parent object that I have made for each of the 4...
  6. huenix

    Issue removing spawn point form available list after taking it

    I am trying to make it so a connected player spawns on an available starting spot (its a board game). It currently works to place them at random points, but they CAN over lap players, i don't want that. How do i remove the available spawn point after "ojb_player" is crated at x/y? if (type...
  7. Slothagami

    SOLVED Multiple expressions in switch statement?

    Can you do something like this? if so how? I will eventually have many commands like this and don't want to have 100+ if statement's if possible // Something like this: if keyboard_check_pressed(vk_enter) { switch keyboard_string { case "START" or "Start" or "start"...
  8. Pelican Police

    Switch case must be a constant (except when it's not).

    Why can't a switch statement use variables from a different instance as cases, when it can use variables from the local instance? I don't see how that's any different? Is it something to do with the compiler automatically spotting constants and swapping them out? This causes Compile failed -...
  9. N

    Windows Switch statement not working.

    Hello community! I have an inquiry regarding how complicated code can get until GameMaker passes on a code the wrong way or fails completely. I have a long sample of code (abridged herein for surveying purposes) that has multiple if and multiple switch statements in an array in which every one...
  10. ac585318

    Question - Code Do case statements require curly braces?

    I'm new to GMS2 and am curious... Do case statements require curly braces? I've seen been going through tutorials and some of them are using curly braces in the case statements and some not. I breifly read that apparently in the C programming language they are needed for declaring variables in...
  11. E

    GML (Minus) Basic maths

    I want to take away 3 from an already set variable in a switch statement. switch (oCharacter.HPdiff){ case 0: oCharacter.Gold = -3 break; This essentially sets the characters gold to -3 instead of removing -3. Game maker doesn't like it if I set it out without the = oCharacter.Gold -3 Any...
  12. F

    GMS 2 Issue with Cutscenes

    I've set up basic cut scenes in my game with the following code. They work in most case but there are two major issues I've run into. 1. I can't have two characters moving at the same time. Since it uses the Switch Statement, action a needs to be completed before action b can start. I tried...
  13. M

    GMS 2 (HELP) switch statement with range of numbers as a case

    im sorry my english is kinda bad, ill try to explain what i need as simply as i can: i want one of the cases in a switch statement to happen in a multiple situations. i want to write something like this (just as an example), but of course it is not how it would work: switch (anim) { case 1,2,3...
  14. H

    GMS 2 Switch statement using all cases

    Hello, I am trying to switch the costume of the player (ball) to corresponding wings costume when colliding with the wings object. For example _________________ Collision event: if global.costume = spr_ball sprite_index = spr_ball_wings if global.costume = spr_ball2 sprite_index =...
  15. K

    GMS 2 [Solved] Trying to get shortcut on switch case statement

    Hi. I wrote this: switch(variable){ //it's a string variable case ("String1"):{ a bunch of code went here break; } case ("String2"):{ a bunch of code went here break; } case ("String3")||("String4")||("String5"):{ a bunch of code went here break; } and so on...
  16. S

    GMS 2 Object animation with code. What command choose.

    Ok i try to make animation in code and have problem with some piece of code. I try in this code make the player sword move from direction 0 [direction 0 is default possition] to max direction but i want the sword if is in 50 [maximum angle] he come back on the position 0 and retry this move if...
  17. E

    Use a "Switch" statement with a "With" construction.

    Sorry if my code is a bit of a mess. I've attempted numerous things without luck and this is what I currently have. case obj_Robot_1: with (obj_Robot_1){ mp_potential_step(obj_Player1.x, obj_Player1.y, 2, true); if obj_Robot_1.y >= room_height /2{ state =...
  18. A

    Ways to make dialogue choices

    I have been doing research on ways to expand upon dialogue. My preferred way is depending on the Q and E buttons for choices. My idea was having a Switch case inside a Switch case. When the dialogue gets to a branch, the buttons lead to another case in the outer switch, and the inner switch is...
Top