ENIGMA Forums

Contributing to ENIGMA => Function Peer Review => Topic started by: polygone on February 27, 2011, 08:17:43 PM

Title: action_move_to
Post by: polygone on February 27, 2011, 08:17:43 PM
Code: (C) [Select]
inline void action_move_to(double x, double y)
{
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  if (argument_relative)
  {
    inst->x += x;
    inst->y += y;
  }
  else
  {
    inst->x = x;
    inst->y = y;
  }
}
How the fuck does relative work? It isn't specified as an argument in gml....
Title: Re: action_move_to
Post by: RetroX on February 27, 2011, 08:42:46 PM
Code: [Select]
inline void action_move_to(double x, double y) { move_towards_point(x, y); }
Title: Re: action_move_to
Post by: Rusky on February 27, 2011, 10:40:02 PM
argument_relative
Title: Re: action_move_to
Post by: RetroX on February 27, 2011, 11:02:38 PM
Code: [Select]
void action_move_to(double x, double y, bool argument_relative)
{
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  if (argument_relative)
  {
    inst->x += x;
    inst->y += y;
  }
  else
  {
    inst->x = x;
    inst->y = y;
  }
}
Title: Re: action_move_to
Post by: IsmAvatar on February 27, 2011, 11:58:14 PM
It's codematically generated when The Plugin translates your DND to code. Immediately prior to the code it will set argument_relative to true if it's relative, or false otherwise.
Title: Re: action_move_to
Post by: polygone on February 28, 2011, 12:03:54 AM
I meant when using action_ functions. In gml the relative argument doesn't seem to be used..
Title: Re: action_move_to
Post by: IsmAvatar on February 28, 2011, 01:40:15 AM
No, I don't think relative is treated as an argument. Instead, it's treated as an internal mechanism, probably not unlike how we've implemented it as a kind of global variable.
Title: Re: action_move_to
Post by: TGMG on February 28, 2011, 10:09:04 AM
This is not the best place to report this but before I forget (I was going to investigate further before filing a bug report). but there is a serious problem with the way the enigma plugin writes the action code.
Before it calls any action it writes the code "argument_relative=true; action_whatever()". Which works fine normally but it doesn't work when the if action is used without the block actions! as this happens:
"if (false) argument_relative=true; action_whatever()"
So it still calls action_whatever even although it shouldn't. I think a similar thing happens with the "with" statement.

It might be better to pass argument_relative into the function as a parameter that has a default value (so it is optional incase its used in normal gml).
Title: Re: action_move_to
Post by: polygone on March 01, 2011, 11:50:28 PM
So I see, you would work relative like so EDL:

Code: (EDL) [Select]
argument_relative = true;
action_move_to(4, 4);
Should use the action relative. This I presume would actually work in gml however it doesn't allow you to set the argument_relative variable.

Calling plain as:
Code: (EDL) [Select]
action_move_to(4, 4);Should always use the action not relative. This means that the argument_relative variable should always be set false after an action is called.
Title: Re: action_move_to
Post by: IsmAvatar on March 02, 2011, 12:21:40 AM
Yes, that's exactly the way it works.
In fact, at one point I had forgotten to reset argument_relative, so we had a bug, but it has since been fixed.
Actually, the way we handle it is to *always* set argument_relative prior to any action that allows relative. Maybe not the most efficient, but I don't think DND users are going to complain about an additional variable set before some DND actions.

However, as TGMG has pointed out, using an IF action before a relative action causes a problem with this conversion method:
* If Action
* Set Motion Relative

gets converted to:
Code: [Select]
if (blah)
  argument_relative = blah;
action_set_motion(blah);

Even though action_set_motion should belong to the if statement.
Solved by either:
Code: [Select]
if (blah)
  { argument_relative = blah; action_set_motion(blah);
or
Code: [Select]
if (blah)
  action_set_motion(blah,argument_relative_value);
Title: Re: action_move_to
Post by: polygone on March 02, 2011, 01:08:05 AM
I've just seen in Universal System:
https://enigma-dev.svn.sourceforge.net/svnroot/enigma-dev/trunk/ENIGMAsystem/SHELL/Universal_System/actions.h

I'm presuming this isn't actually called, but will be?
Title: Re: action_move_to
Post by: TGMG on March 02, 2011, 06:05:26 AM
@IsmAvatar I initially tried to solve the problem by changing the plugin to add "{" around it. But it causes a problem when using multiple if statements:
{argument relative=false //this argument_relative is part of the action_if_something
if(action_if_something()) { //can't close the '}' for argument_relative until the end
{argument relative=false //this argument_relative is part of the action_if_something
if(action_if_something()) {
{argument relative=false
if(action_if_something()) {
{argument relative=false
action_something();}
}}}}}} //close al the if statements and the argument_relative blocks

So it needs to keep track of where to actually close the '{' for action_if's (that have the relatvie checkbox) which is much more complex than passing the value in by the argument.

@polygone: I forgot that file was still in enigma, it isn't included, it provides all the function prototypes so i can easily test out game maker games which use actions without actually implementing each action properly. As you can see its very messy and unoptimised, it was really just a way to quickly test games that otherwise wouldn't convert.
Title: Re: action_move_to
Post by: polygone on March 02, 2011, 11:40:32 AM
Quote
So it needs to keep track of where to actually close the '{' for action_if's (that have the relatvie checkbox) which is much more complex than passing the value in by the argument.
Can't you put the closing brace in then move back up into the statements?
Title: Re: action_move_to
Post by: TGMG on March 02, 2011, 12:11:57 PM
I don't understand what you mean by moving back up into the statements :/
Title: Re: action_move_to
Post by: Rusky on March 02, 2011, 12:38:15 PM
Keeping track of braces is trivial if you're not doing a find-and-replace parser, which I hope is the case by now.
Title: Re: action_move_to
Post by: TGMG on March 02, 2011, 12:45:58 PM
Implementing a parser just for writing the action code to gml would be overkill and be very unnecessary unless their is a reason to not pass the argument_relative in as an argument, which only requires changes 2 or 3 lines of code in the plugin compared to writing a parser or implementing code to keep track of the closing braces.
Title: Re: action_move_to
Post by: IsmAvatar on March 02, 2011, 02:01:35 PM
Personally I'm a fan of passing an argument, as long as it doesn't introduce problems with variable arguments or such. It makes sense that way, since relative is kind of an 'argument' to the DND action, and not intended as a global variable. It saves the trouble of keeping it global. And, the conversion process is intended to mostly reflect the DND look, so introducing brackets muddies it up, since that's really only supposed to be introduced by the Begin and End (resp. up and down triangle) actions.
Title: Re: action_move_to
Post by: polygone on March 02, 2011, 02:36:36 PM
I'm failing to see how it will work without overcomplicating things since when the gml action_* functions don't take the relative argument.
Title: Re: action_move_to
Post by: IsmAvatar on March 02, 2011, 03:56:50 PM
polygone: Function overloading is possible in C++ (the language ENIGMA is written in).

action_single_argument(var arg1)
action_single_argument(var arg1, bool argument_relative)

Or, sometimes this is written:
action_single_argument(var arg1, bool argument_relative = false)
To indicate a default value if none is provided.
Title: Re: action_move_to
Post by: polygone on March 02, 2011, 04:22:46 PM
Oh using a default parameter is fine then?

Code: (C) [Select]
inline void action_move_to(double x, double y, bool argument_relative = false)
{
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  if (argument_relative)
  {
    inst->x += x;
    inst->y += y;
  }
  else
  {
    inst->x = x;
    inst->y = y;
  }
}
You won't need argument_relative as a global variable then. Why wasn't this just used to start with?
Title: Re: action_move_to
Post by: IsmAvatar on March 02, 2011, 04:55:26 PM
I come from a C background, where functions cannot be overloaded. The action_* functions included in GM do not have these arguments.
Title: Re: action_move_to
Post by: Josh @ Dreamland on March 03, 2011, 12:04:05 AM
You can use that for now. Until TGMG commits his changes, which include an argument_relative. See the discussion in this thread (http://enigma-dev.org/forums/index.php?topic=768).