There is a maximum amount of states apparently:
Images can only have a max of 30 states[1]
you should just loop through stateName0 to stateName30
And here's my code changed to reflect this knowledge!
function WeaponImage::getImageStateNo(%this, %stateName)
{
if (%stateName $= "Error")
return -1;
for(%i=0;%i<=30;%i++) //There is a maximum of states an image can have (31 in total, so 0 to 30)
{
if (%this.stateName[%i] $= %stateName)
return %i;
}
return -1;
}
If the name given is Error or if it cannot find the given name, it will return -1 which is of course an impossible state number.
If it does find a state with that name, it will return the right number.
Hope this helps someone else as well!
Original postGreetings again, i am here with more of a question/discussion about how to do something.
The thing is, we can get the name of the state an image is in by using getImageState, however, this returns the name, not the number.
How could we find the number efficiently?
For all i know, the image could have the state with that name on number 999999 in the stateName array for no apparent reason.
And i know people SHOULD not do that and just use numbers in sequence, but i have seen before that some images use numbers that are out of the sequence.
For example, Deadzone's melee weapons have some that have no 8th state, but they do have a 9th state for example.
So this rules out a while loop that stops if it finds an empty spot in the array.
Is there any other way to do this aside from running a while loop until you find the state with that name?
Here's how i search for it right now for whatever reasons needed:
function WeaponImage::getImageStateNo(%this, %stateName)
{
if (%stateName $= "Error")
return -1;
%i = 0;
%found = 0;
while(!%found)
{
if (%this.stateName[%i] $= %stateName)
{
%found = 1;
return %i;
}
%i++;
}
}
I was not sure if the return would also stop the while loop so just to be sure i made something that makes sure it won't go on...
But this is pretty much an infinite loop until it finds the right thing.
If that does not exist, though luck, have fun having a crashing blockland. :X
Were it not for the low amount of stuff happening in the while loop, i would be afraid this was very prone to lagging/freezing the game.