object is unown

___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.sprite_index(25, -2147483648) not set before reading it.
at gml_GlobalScript_playerAnimateSprite (line 3) - var _totalFrames = sprite_get_number(sprite_index)/ 4;
############################################################################################
gml_GlobalScript_playerAnimateSprite (line 3)




this is The error i am getting.





//Upate Sprite
var _cardinalDirection = round(90);
var _totalFrames = sprite_get_number(sprite_index)/ 4;
image_index = localFrame + (_cardinalDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index)/ FRAME_RATE;

//If Animation Woud Loop on Next Game Step
if (localFrame >= _totalFrames)
{
animationEnd = true;
localFrame -= _totalFrames;

} else animationEnd = false;












this is the file its giving error for ig. I have just started using gml, i used to work with dnd earlier.
 

Roldy

Member

 
What the guys above meant is for you to do this :
Untitled.png
Makes it easier for everyone to see your code.

i am new to gml and idk what u are exactly trying to say so can I can give you my source code and assets
Rarely will anyone bother downloading your source code and do a fix for you, unless the person helping specifically offer to do so. Best you post the relevant codes instead.
 
yes i did but i didn't understand exactly what they mean
What it meant is that there are some format changes between before GMS2 IDE version 2.3 and current version. Thus new users or everyone in general need to know how to adapt old source code (in this case for those trying to use old tutorials) to meet the new format requirement to make it run properly.

Do you have a script name " gml_GlobalScript_playerAnimateSprite ". Post that too.
 
GML:
//Upate Sprite
var _cardinalDirection = round(90);
var _totalFrames = sprite_get_number(sprite_index)/ 4;
image_index = localFrame + (_cardinalDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index)/ FRAME_RATE;

//If Animation Woud Loop on Next Game Step
if (localFrame >= _totalFrames)
{
    animationEnd = true;
    localFrame -= _totalFrames;
    
} else animationEnd = false;




this is the script supposedly having error.
 
What it meant is that there are some format changes between before GMS2 IDE version 2.3 and current version. Thus new users or everyone in general need to know how to adapt old source code (in this case for those trying to use old tutorials) to meet the new format requirement to make it run properly.

Do you have a script name " gml_GlobalScript_playerAnimateSprite ". Post that too.
i did jjust now
 
Did you assign to "sprite_index" which sprite it is supposed to be accounting for in either a script or in the create event? Because that's what the issue is, it's not returning a value. for _TotalFrames to use.
 
Did you assign to "sprite_index" which sprite it is supposed to be accounting for in either a script or in the create event? Because that's what the issue is, it's not returning a value. for _TotalFrames to use.
GML:
//Get Player Input
keyLeft = keyboard_check(vk_left) || keyboard_check(ord("A"));
keyRight = keyboard_check(vk_right) || keyboard_check(ord("D"));
keyUp = keyboard_check(vk_up) || keyboard_check(ord("W"));
keyDown = keyboard_check(vk_down) || keyboard_check(ord("S"));
keyActivate = keyboard_check_pressed(vk_space);
keyAttack = keyboard_check_pressed(vk_shift);
keyItem = keyboard_check_pressed(vk_control);

inputDirection = point_direction(0,0,keyRight-keyLeft,keyDown-keyUp);
inputMagnitude = (keyRight - keyLeft != 0) || (keyDown - keyUp != 0);

//Movement
hspeed = lengthdir_x(inputMagnitude * SpeedWalk,inputDirection);
vspeed = lengthdir_y(inputMagnitude * SpeedWalk,inputDirection);

x += hspeed;
y += vspeed;

//Update Sprite Index
var _oldSprite = sprite_index;
if (inputMagnitude != 0)
{
    direction = inputDirection;
    sprite_index = spriteRun;
} else sprite_index = spriteIdle;
if (_oldSprite != sprite_index) localFrame = 0;

//Updating Image index
playerAnimateSprite();




here i have assigned gml playeranimatesprite to step for player sprite.
 

chamaeleon

Member
It doesn't matter if the code is 100% and all variables are used correctly if the advice in the link in the first reply is not followed.
 

Roldy

Member
how to implement it ?


???
Read the link:


If you don't understand it then ask specific question about what you don't understand.
 
Read the link:


If you don't understand it then ask specific question about what you don't understand.
Thank you very much . I got it.


Thanks everyone for helping
 
Top