Author Topic: [SOLVED] Getting the current state of an image  (Read 1253 times)

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!
Code: [Select]
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 post
Greetings 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:
Code: [Select]
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.
« Last Edit: June 19, 2016, 06:11:41 AM by lordician »

I'm pretty sure there's a max of like, 30 states or something along those lines.

returns will break the loop; so will break; if you want to put something after the loop to run

I'm pretty sure there's a max of like, 30 states or something along those lines.
This would make it a lot easier.
I will have to do some searching to check this, but if anyone can confirm, that would be great.
returns will break the loop; so will break; if you want to put something after the loop to run
Figured, but alright.

Images can only have a max of 31 states[1]

you should just loop through stateName0 to stateName30
« Last Edit: June 20, 2016, 09:14:32 PM by Swollow »

Images can only have a max of 30 states[1]

you should just loop through stateName0 to stateName30
Thanks a lot!

Once again, modified the original post with the solution and my code for it for documentation purposes.
Thanks a lot again guys.
« Last Edit: June 19, 2016, 06:12:53 AM by lordician »

I think you can use continue; to stop the current iteration of the loop but continue doing it after it stops that iteration just for future reference.

A break would have been more useful (if return did not already break the loop), but it is good to know.
I always forget about break, continue and all that. :X