ID:144290
 
Code:
    icon='gold.dmi'
if(usr.wealth==1)
icon_state="1"
if(1<usr.wealth<=10)
icon_state="2"
if(10<usr.wealth<=50)
icon_state="3"
if(50<usr.wealth<=100)
icon_state="4"
if(100<usr.wealth<=500)
icon_state="5"
if(500<usr.wealth<=10000)
icon_state="6"
if(wealth>10000)
icon_state="7"


Problem description:
I put this in my code, but the only icon_state that ever comes up is 5. I am already certain that the problem is not where i put it, and i have not changed it's icon_state anywhere else... WHAT THE HECK IS WRONG!?
1<x<10 works great in math, but not so great in programming. You need to check each condition seperately. Ex: if(variable < 10 && variable > 2) (the && means and)

You could also use switch(), that allows you to do stuff like that. Ex:
switch(somevar)
if(1 to 3)
// stuff here
if(4 to 14)
// stuff here
else
// other stuff here
In response to Jon88
Jon88 wrote:
1<x<10 works great in math, but not so great in programming. You need to check each condition seperately. Ex: if(variable < 10 && variable > 2) (the && means and)

You could also use switch(), that allows you to do stuff like that. Ex:
switch(somevar)
> if(1 to 3)
> // stuff here
> if(4 to 14)
> // stuff here
> else
> // other stuff here


With a var like wealth this would probably be a bad move, because the values may not strictly be integers. The best way to handle this would be to simply modify the original if() statements:

if(wealth>100 && wealth<=500)
...


Lummox JR
There are four problems with your code as it stands right now:

  • if(1<var<=10) is not valid in any programming language I know of. This is a math construct, not code. In code, 1<var gets interpreted first, and becomes 0 or 1 (in some langauges a true value is -1), and then that is compared to 10. The correct way to handle this is if(var>1 && var<=10) instead.
  • You don't account for 0 anywhere in your code, nor is there a failsafe for negative values. (Likewise, you aren't handling the cases from just above 0 up to 1, like 0.5.)
  • This entire thing would be much better handled with else ifs. E.g., if(wealth<=0), then else if(wealth<=1), else if(wealth<=10), etc., then finally a basic else for the >10000 case.
  • No put usr in proc. Ungh.

    Lummox JR