Pages: 1
  Print  
Author Topic: Action functions plugin writing  (Read 39547 times)
Offline (Unknown gender) TGMG
Posted on: March 01, 2011, 12:08:15 pm

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
Currently a few issues are caused by the way the enigma plugin write the actions into gml. Mostly due to the handling of "argument_relative" and possibly the writing of with statements.

Currently the lgm plugin will transform an action that has a relative checkbox into:
argument_relative=true
action_something()

Which causes a problem when the action_if is used without the block actions as it will produce:
if(false)
argument_relative=true
action_something()

So it will always call action_something even when the expression is false.
One way to solve this is to make the plugin automatically put both statements in a block which works fine apart from if statements that use the relative checkbox.
Since some if actions use relative the resulting code for alot of nested if statements would be:
if(action_if())
argument_relative=true
if(action_if_something())
argument_relative=false
if (action_if_something())

Which clearly doesn't work without the block actions.

The action_if_something is just any if action which has a relative checkbox.

So I propose the easiest solution to this would be taking in the argument_relative as an optional parameter for all the action functions, like so:
if(action_if())
if(action_if_something(arguments,true)) //true for relative
if (action_if_something(arguments,false))

You have to implement the action_if actions in order to see this effect otherwise enigma will complain about the functions not existing.
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Male) polygone
Reply #1 Posted on: March 01, 2011, 10:49:05 pm

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
Why is argument_relative not passed as a function parameter from actions?
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) RetroX
Reply #2 Posted on: March 01, 2011, 10:50:22 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
I believe that it's done that way because of how the GML format is stored.  Otherwise, it probably would have been passed as a parameter.
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Male) polygone
Reply #3 Posted on: March 01, 2011, 11:31:00 pm

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
Why are the argument_* global variables a different scope to the rest of the global variables? I can't use them inside function definitions...
« Last Edit: March 01, 2011, 11:34:15 pm by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Female) IsmAvatar
Reply #4 Posted on: March 01, 2011, 11:33:55 pm

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 877

View Profile Email
polygone: Try to stay on topic here. Your question isn't really relevant. To answer your question, though, you should be able to use it. However it may not be defined in enigma, so it may be necessary to define it as a bool argument_relative in Definitions in order to use it.
Logged
Offline (Unknown gender) TGMG
Reply #5 Posted on: March 02, 2011, 04:38:17 am

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
You can use it if you add it to the globals file, which I have done but deliberately not added to svn because of the problem I mention in this topic. The way to implement action functions may change as a result of this.

Does anyone have any objections to implementing the action functions like so:
void action_func( int required, bool argument_relative = false ) {}

Which means you can still call the function without the argument_relative parameter and it will fix the issue without having to figure out where the ending '}''s go with lots of nested action_ifs with argument_relatives.
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Female) IsmAvatar
Reply #6 Posted on: March 02, 2011, 02:18:03 pm

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 877

View Profile Email
What is int required?

As I said in the other topic, I'm fine with it as long as it doesn't introduce problems with variable arguments and such.
Logged
Offline (Male) Josh @ Dreamland
Reply #7 Posted on: March 02, 2011, 09:40:46 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
If I may bud in, we have plenty of solutions to this issue.

1. Encase everything in {}.
{ argument_relative = true; action_do_shit(); }
2. Comma.
argument_relative = true, action_do_shit();
3. Parentheses and comma. This will solve if().
if((argument_relative=true, action_if(fuck_you)))
  ;

You'll find this more accurately mimics GM's behavior. Particularly the last one. (argument_relative = false, do_shit()) is rather form-fitting, syntactically.

IsmAvatar: `int required` is the required parameter. Int was an example. He was implying that the function would be backwards compatible, but would allow LGM to set an argument relative. I object because the additional stack push and assignment is baloney.
« Last Edit: March 03, 2011, 12:07:53 am by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Female) IsmAvatar
Reply #8 Posted on: March 03, 2011, 02:11:36 am

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 877

View Profile Email
if((argument_relative=true, action_if(fuck_you)))
  ;

That really works? Done.
Logged
Offline (Male) Josh @ Dreamland
Reply #9 Posted on: March 03, 2011, 09:23:35 am

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
Indeed. Even if it didn't, we could use && instead of the comma for true, and || instead of it for false, in the case of if().
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) polygone
Reply #10 Posted on: March 03, 2011, 10:13:46 am

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
I don't get? Isn't it just better to pass it as an argument anyway? It seems preferable for function calling.
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Unknown gender) TGMG
Reply #11 Posted on: March 03, 2011, 11:35:33 am

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
I would love that solution if it wasn't for the problem of GM conversion. The plugin only writes gml which is then passes to the enigma parser, which means that any system which maps = to == in expressions would fail.
It wouldn't matter but the huge number of gm games I have looked at use = in expression when they actually mean ==, the compile only picks up some of these as many of them are valid c++ which leads to logic errors which are a pain to debug.
But if the plugin is now passing an actual assignment in an expression how will this system work?
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Male) RetroX
Reply #12 Posted on: March 08, 2011, 04:09:15 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Hey, TGMG.  Please inline functions in actions.h by prefixing them with the word "inline."  The one-line ones, anyways.
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) TGMG
Reply #13 Posted on: March 08, 2011, 04:37:00 pm

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
Ah yes thanks RetroX, fixed now :)
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Pages: 1
  Print