ENIGMA Development Environment
Website is in read-only mode due to a recent attack.

Pages: 1
  Print  
Author Topic: Getting min and max of variables without min and max.  (Read 1688 times)
Offline (Unknown gender) crxtrdude
Posted on: December 24, 2015, 11:47:06 AM
Member
Joined: Dec 2015
Posts: 22

View Profile WWW
I want to use min and max on my own variables (in the example is hsp) and it had the error:

Quote
error: 'hsp' was not declared in this scope

Also in subsequent variables as well.

Is there a way to do something like this without using min and max? I'm using this in a script. I think it's related to this issue.
« Last Edit: December 24, 2015, 11:50:54 AM by crxtrdude » Logged
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: December 25, 2015, 05:39:53 PM

Developer
Joined: Apr 2008
Posts: 1860

View Profile
If that is the parser bug, then you cannot use instance local variables. You can create temporary variables (like "var thsp" or "double thsp") and use that, or you can just use fmin() and fmax() which will work (and be even faster) with two variables. The problem why max and min is broken is because they use something called "varargs" or "variable number of arguments". This means that you can have almost unlimited number of variables in these functions (like "min(a,b,c,d,e,f,g,i,j and son)" but they are not working with instance variables because the parser has a bug. Sadly I cannot fix it without rewriting the parser and that is something I cannot realistically do.
Logged
Offline (Unknown gender) crxtrdude
Reply #2 Posted on: December 26, 2015, 09:49:09 AM
Member
Joined: Dec 2015
Posts: 22

View Profile WWW
Oh, okay. Well, I did a rewrite on my code that is different from what I currently do. In fact, I adopted the Grandma Engine for platformers now and it's approach script (which uses min and max, but is passed as arguments) mysteriously worked. Is that they are passed as arguments (argument0 and the like) and not act as instance locals?
« Last Edit: December 26, 2015, 09:50:44 AM by crxtrdude » Logged
Offline (Unknown gender) TheExDeus
Reply #3 Posted on: December 29, 2015, 07:26:37 PM

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Yes, argument0,1,2 etc. are local script variables, so they don't have any problem.
Logged
Pages: 1
  Print