Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

choose() function [u524]/Variadic varargs #214

Closed
EnigmaBot opened this issue Jun 14, 2013 · 13 comments
Closed

choose() function [u524]/Variadic varargs #214

EnigmaBot opened this issue Jun 14, 2013 · 13 comments
Assignees
Labels
Bug Issues that are non fatal and occur at run time or compile time. Compiler Syntax checking, JDI, and code generation. Confirmed The issue has been confirmed as existing by another user or contributor. Parsing Syntax checking, preliminary parsing, and code generation. Reproducible Can be triggered determininistically by a discrete series of steps. Universal System Resource storage and other logic universal to more than one system or extension.
Milestone

Comments

@EnigmaBot
Copy link

(Posted by time-killer-games on the ENIGMA forums)

The choose() gml function isn't implemented in enigma properly. There needs to be a way to have any number of arguments on a range from 2 to the argument limit (which I think in GM is 16?). I'm trying to port a game made by a friend of mine to Linux but can't because of the errors related to his use of the choose() function.

@TheExDeus
Copy link
Member

I think it did work before, but I also noticed that it is broken now. Works with only 2 or so arguments.

@fundies
Copy link
Contributor

fundies commented Jun 14, 2013

I had a similar issue with mean when josh switched out the C parser. Probably needs the same fix.

@forthevin
Copy link
Member

The bug occurs only when you try using a variable, not a literal, as an argument for the choose function inside a script. Outside a script, or only using literals, choose works correctly.

@EnigmaBot
Copy link
Author

(Posted by Josh @ Dreamland on the ENIGMA forums)

I can't even believe that's true. I'm afraid to say that fixing this would be finding a needle in a haystack; I'm setting the milestone to enigma-jdi, wherein the mechanism scripts use to access locals will not interfere with the enigma::varargs mechanism. I should apologize now for the delay. As a workaround, try declaring each parameter as a script-local, though it sounds like that might not help.

@ghost ghost assigned JoshDreamland Jun 15, 2013
@RobertBColton
Copy link
Contributor

RobertBColton commented Dec 14, 2014

I have done some regression testing on this issue.
https://www.dropbox.com/s/lil7mdx4eysuhf6/scriptchoosevariable.gm81?dl=0

Create event:

a = 1;
b = 2;
c = 3;

Step event:

if (keyboard_check_released(vk_space)) {
  show_message(choose(a,b,c));
  show_message(choose(1,2,3));
  show_choose_message();
}

show_choose_message() script:

show_message(choose(a,b,c));
show_message(choose(1,2,3));
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:39:43: error: 'a' was not declared in this scope
   show_message(choose((enigma::varargs(), a, b, c)));
                                           ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:39:46: error: 'b' was not declared in this scope
   show_message(choose((enigma::varargs(), a, b, c)));
                                              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:39:49: error: 'c' was not declared in this scope
   show_message(choose((enigma::varargs(), a, b, c)));
                                                 ^

@RobertBColton RobertBColton added Reproducible Can be triggered determininistically by a discrete series of steps. Compiler Syntax checking, JDI, and code generation. Universal System Resource storage and other logic universal to more than one system or extension. labels Dec 14, 2014
@TheExDeus
Copy link
Member

It's not only choose, but min, max, median and so on. I have reported this before, most recently here: http://enigma-dev.org/forums/index.php?topic=1860.0
The problem is that the parser doesn't take the correct variable. If you did "var sa = a, sb = b, sc = c" and then choose(sa,sb,sc), then it would work.

@RobertBColton
Copy link
Contributor

@sorlok Do you think you could possibly offer some insight into how this functionality broke? I'm just wondering since you seem really good about offering a new perspective on old issues.

@sorlok
Copy link
Contributor

sorlok commented Dec 24, 2014

Well, I'm not sure how it broke, but I think @TheExDeus describes the issue perfectly. The parser doesn't tag variables inside functions correctly. Which means a grueling parser debug to fix this bug.

@RobertBColton
Copy link
Contributor

Hmmm, the problem is I would try to fix it but I don't even know where to start really. It's a part that I am unfamiliar with, but I guarantee it's a simple fix. @JoshDreamland Should offer some clues for where to look.

@TheExDeus
Copy link
Member

I doubt this "broke". I think it never worked. I made a topic about this issue in April, but I mentioned it before last year or even a year before that. So as far as I'm aware this was never fixed/implemented.

Basically you need to check variables inside the vararg functions and see if instances has them as locals or if you need to create a temporary one. I guess the problem here is the vararg's (functions with variable number of arguments) which are not properly handled in current parser.

@RobertBColton RobertBColton changed the title choose() function [u524] choose() function [u524]/Variadic varargs Apr 24, 2016
@RobertBColton RobertBColton added the Parsing Syntax checking, preliminary parsing, and code generation. label Apr 24, 2016
@RobertBColton
Copy link
Contributor

Another workaround discovered in #914 is the following:

var yolo,swag;
swag = self.swag;

@RobertBColton
Copy link
Contributor

RobertBColton commented Jun 14, 2016

I should add that this issue was also a duplicate of #5 which was already a known parser bug.

@RobertBColton
Copy link
Contributor

RobertBColton commented Sep 14, 2016

I should mention too that I think the Wiki article about varargs is outdated.
http://enigma-dev.org/docs/Wiki/Varargs

And just plain choose(1,2,3) in an empty game throws an exception on compile (a Java exception invokeInt) but show_message(choose(1,2,3)); does not.

JoshDreamland added a commit that referenced this issue Sep 17, 2016
Use 'n' instead of 't' so the declaration crawler doesn't mistake varargs for a declaration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that are non fatal and occur at run time or compile time. Compiler Syntax checking, JDI, and code generation. Confirmed The issue has been confirmed as existing by another user or contributor. Parsing Syntax checking, preliminary parsing, and code generation. Reproducible Can be triggered determininistically by a discrete series of steps. Universal System Resource storage and other logic universal to more than one system or extension.
Projects
None yet
Development

No branches or pull requests

7 participants