Pages: 1
Author Topic: Getting min and max of variables without min and max.  (32,149 Views)
Offline (Unknown gender) crxtrdude

Member
Joined: Dec 2015
Posts: 22
View profile WWW
Posted on: December 24, 2015, 04:47:06 PM
I want to use min and max on my own variables (in the example is hsp) and it had the error:

Quoteerror: '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.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: December 25, 2015, 10:39:53 PM
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.
Offline (Unknown gender) crxtrdude

Member
Joined: Dec 2015
Posts: 22
View profile WWW
Reply #2 Posted on: December 26, 2015, 02:49:09 PM
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?
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #3 Posted on: December 30, 2015, 12:26:37 AM
Yes, argument0,1,2 etc. are local script variables, so they don't have any problem.
Pages: 1