1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Drag And Drop (SOLVED) How to put "or" argument into Drag and Drop text boxes?

Discussion in 'Programming' started by Colorized, May 13, 2019.

  1. Colorized

    Colorized Member

    Joined:
    Mar 2, 2019
    Posts:
    21
    I have this "if key pressed" block that has a W input in it. How do I make it say, for example, W or space?
    [​IMG]
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,960
    Use the If Expression action instead and put the equivalent GML expression there.
    Code:
    keyboard_check_pressed(ord("W")) || keyboard_check_pressed(vk_space)
     
  3. Colorized

    Colorized Member

    Joined:
    Mar 2, 2019
    Posts:
    21
    Nvm, could just put ord("W")||vk_space
     
  4. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    236
    That doesn't do the same thing.
    ord("W") is 87
    vk_space is 32
    Therefore, ord("W") || vk_space = 87 || 32 = 1
    Basically, you're checking a key that doesn't exist on keyboards. Code isn't English; you can't treat it as such. You'll have to do what FrostyCat says and separate the expressions:
    Code:
    keyboard_check_pressed(ord("W")) || keyboard_check_pressed(vk_space)
    
     
  5. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    830
    If you wanted to stick entirely to DND you could do it like this:
     

    Attached Files:

    RefresherTowel likes this.
  6. Colorized

    Colorized Member

    Joined:
    Mar 2, 2019
    Posts:
    21
    That's cool n all, but it still worked like this:
    [​IMG]
     
  7. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    236
    It works because vk_anykey is equivalent to 1. Try pushing any other key on the keyboard to see if it works.
     
  8. Colorized

    Colorized Member

    Joined:
    Mar 2, 2019
    Posts:
    21
    Where are you getting the vk_anykey from?
     
  9. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    236
    Because
    Code:
    if keyboard_check(ord("W") || vk_space)
    
    is exactly the same as typing
    Code:
    if keyboard_check(vk_anykey)
    
    When you type "ord("W") || vk_space", you aren't polling both the W and Space keys. You're checking if either ord("W") or vk_space are true. In GM, all numbers >= 0.5 are equivalent to true, or 1. Both ord("W") and vk_space are larger than 0.5, so (ord("W") || vk_space) always returns true. True is equivalent to 1. Guess which GM keyword is equivalent to 1? vk_anykey.

    EDIT: See this tutorial if you have any further questions about using ||: https://forum.yoyogames.com/index.php?threads/how-not-to-use-and.12871/
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice