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

Pkirkby

Member
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.
 
  • Wow
Reactions: Mut

TheouAegis

Member
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.
 

Pkirkby

Member
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.
 

Pkirkby

Member
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.
 
T

Taddio

Guest
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.
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 !=
 

Pkirkby

Member
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.
 
T

Taddio

Guest
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;}
 

Pkirkby

Member
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;}
 
D

dannyjenn

Guest
Oh I would have never guessed, thanks alot.
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.
 

Pkirkby

Member
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.
 
Top