ENIGMA Forums

Outsourcing saves money => Programming Help => Topic started by: crxtrdude on December 24, 2015, 11:47:06 am

Title: Getting min and max of variables without min and max.
Post by: crxtrdude on December 24, 2015, 11:47:06 am
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 (https://github.com/enigma-dev/enigma-dev/issues/5) issue.
Title: Re: Getting min and max of variables without min and max.
Post by: TheExDeus on December 25, 2015, 05: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.
Title: Re: Getting min and max of variables without min and max.
Post by: crxtrdude on December 26, 2015, 09:49:09 am
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 (https://forums.tigsource.com/index.php?topic=5790.0) 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?
Title: Re: Getting min and max of variables without min and max.
Post by: TheExDeus on December 29, 2015, 07:26:37 pm
Yes, argument0,1,2 etc. are local script variables, so they don't have any problem.