ENIGMA Forums

General fluff => General ENIGMA => Topic started by: RetroX on October 30, 2010, 04:13:21 pm

Title: DnD Functions
Post by: RetroX on October 30, 2010, 04:13:21 pm
Not like anyone here uses DnD, but they might as well be done. :P

#define action_if(x) if(x)
#define action_while(x) while(x)

etc.
Title: Re: DnD Functions
Post by: IsmAvatar on October 31, 2010, 09:00:56 pm
I'm not completely sure, but this might fall apart when the user selects "not". Judging by the way I coded LGM to handle it, I think action_if, when passed "x" and having "not" selected, LGM will generate the following code:

if !action_if(x)

Which would make yours generate the following code after resolving the defines:

if !if(x)

Perhaps a better solution might be

inline boolean action_if(var x) { /* return x != 0 */ }
or
#define action_if(x) (x != 0)
Title: Re: DnD Functions
Post by: RetroX on November 01, 2010, 03:55:46 pm
That works.  I personally didn't know how LGM handled it, and assumed that action_if() was just used as an if macro.
Title: Re: DnD Functions
Post by: Josh @ Dreamland on November 01, 2010, 08:20:16 pm
...
LGM should handle action_if itself, without writing action_if.
I am unsure of the function of action_if in a GML script. Can someone verify it?
Title: Re: DnD Functions
Post by: IsmAvatar on November 01, 2010, 09:30:00 pm
The problem is that there are different conditional actions, and action_if is just a function name. For conditional actions, I do already prepend "if" for it, and then handle "not" by also prepending "!". The function then follows, so it's simple enough to just write the code for it, but I can't assume that action_if is necessary the if action, because it could very well be user coded with special conditions, in which case it should simply behave as a "return x != 0;"
Title: Re: DnD Functions
Post by: Josh @ Dreamland on November 02, 2010, 12:31:06 am
If it's not the case that action_if is a substitute for "if", then it should be defined as inline bool action_if(double x) { return x >= .5; } (bool(x != 0) is redundant, anyway).
Title: Re: DnD Functions
Post by: IsmAvatar on November 02, 2010, 09:27:02 am
Don't forget negative numbers.
Title: Re: DnD Functions
Post by: Josh @ Dreamland on November 02, 2010, 09:33:06 am
bool(-1) = 0 in GML
Title: Re: DnD Functions
Post by: IsmAvatar on November 02, 2010, 09:37:28 am
works for me
Title: Re: DnD Functions
Post by: Rusky on November 02, 2010, 11:39:38 am
How are you planning to deal with that in GML? If you directly copy the if over the truth of expressions will be different.
Title: Re: DnD Functions
Post by: IsmAvatar on November 02, 2010, 11:45:42 am
For example?
Title: Re: DnD Functions
Post by: Josh @ Dreamland on November 02, 2010, 12:34:26 pm
variant::operator bool() { return dval > .5; }
Title: Re: DnD Functions
Post by: polygone on November 02, 2010, 12:39:38 pm
Can there be an option added to LGM/Enigma to make it x != 0 instead of x <= .5 ?
Title: Re: DnD Functions
Post by: Josh @ Dreamland on November 02, 2010, 12:41:34 pm
Ideally. At this point, options are still a YAML clusterfuck. But after we have it so you're able to switch out APIs, I don't see why not.
Title: Re: DnD Functions
Post by: RetroX on November 03, 2010, 03:28:09 pm
variant::operator bool() { return dval > .5; }
Shouldn't that be >=?
Title: Re: DnD Functions
Post by: Josh @ Dreamland on November 04, 2010, 12:09:35 am
It is, I just wasn't paying much attention to the thread. :P