1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

How to do "AND" "OR" and "XOR" in drag and drop

Discussion in 'Programming' started by Pkirkby, Mar 29, 2019.

Tags:
  1. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    I've kind of got the hang the drag and drop hierarchy, however I'm trying to do an "&&" statement in drag and drop logic and I can't figure it out. Can anyone help make sense of this?

    Thanks in advance.
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,148
    AND is just two or more conditionals in a row.

    For the others, I'd just use Test Expression, which lets you type out GML conditions without leaving D&D.
     
  3. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    Oh ok, the only reason I didn't think that because when I convert it to GML it didn't look like "&&" but I know very little about coding, so that's my issue. Thanks alot.
     
  4. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    Do you think you could show me a very simple example? I'm not sure how to lay it out in DND. For example, I want to accomplish this in DND:
    if (floor(image_index) == 5 && sprite_index == spr_attack)

    ignore the floor part, as it's just code I copied from someone else. Essentially I'm trying to get my attack animation to stop looping, and return to the idle right standing pose.
     
  5. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    463
    That code would work, why not just drag an "execute code" box in there?
    And I do suggest you floor() or round() image_index when comparing like that, or use >=, <= and !=
     
  6. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
     
  7. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    I may do that, but I'm trying to understand what "floor" is. I'd really like to understand it in DND so I can lay it out simply, then interpret it in code one day down the line. A picture of the DND logic is and how it's laid out helps me visually. Thanks for the response.
     
  8. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    463
    Floor is rounding to the lowest integer, and round() brings it to the nearest.

    floor(3.9); //will return 3
    round(3.9); // will return 4

    When dealing with image indexes, they are not always equal to an integer (you can be on image_index 1.000001 for a frame), so in these cases thats why it wont work if you'd do
    if(image_index == 1) {//do something;}
     
  9. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
     
  10. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    Oh I would have never guessed, thanks alot.
     
  11. dannyjenn

    dannyjenn Member

    Joined:
    Jul 29, 2017
    Posts:
    572
    Just making sure, but, you do know that there's a help file, right? You can use that to look up any function you aren't familiar with. Get to the help file through Help > Open Manual. (It's also online at https://docs2.yoyogames.com/ ... I think the online version might be a little more up to date.)


    Anyway, I don't believe that Drag and Drop has an and statement or a floor() function. For that stuff, you'd just type it all into the 'if variable' action, and use true as the value. I think.
    Screen Shot 2019-03-29 at 8.07.34 AM.png


    Another way to get the same result is to use a nested if statement.
    Screen Shot 2019-03-29 at 8.05.56 AM.png
    However, the nested if statement and the and statement are not interchangeable. In this simple example they are (both will get the same result), but generally speaking they aren't. Because as soon as you add an else statement, the nested if statement no longer behaves as an and statement.
     
  12. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    Ok that's really helpful, I'll try that when I'm home. I tried a few things like that but no luck. Appreciate your answer.
     

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