GameMaker Studio中的变量问题

时间:2016-10-13 22:36:45

标签: game-maker

在obj_player上我有一个创建和步骤事件

创建:

/// Intialize Variables      
grav = 0.2;      
hsp = 0;     
vsp = 0;      
jumpspeed = 7;     
movepseed = 4;    
key_left = 0;
key_right = 0;
move = key_left + key_right;    

步骤:

//Get the player's input       
key_right = keyboard_check(vk_right);      
key_left = -keyboard_check(vk_left);    
key_jump = keyboard_check_pressed(vk_space);     

//React to inputs      
move = key_left + key_right;      
hsp = move * movespeed;      
if (vsp < 10) vsp += grav;      

if (place_meeting(x,y+1,obj_wall))        
{         
    vsp = key_jump * -jumpspeed        
}        

//Horizontal Collision     
if (place_meeting(x+hsp,y,obj_wall))         
{       
    while(!place_meeting(x+sign(hsp),y,obj_wall))       
    {          
        x += sign(hsp);        
    }       
    hsp = 0;         
}               
x += hsp;       

//Vertical Collision     
if (place_meeting(x,y+vsp,obj_wall))     
{        
    while(!place_meeting(x,y+sign(vsp),obj_wall))    
    {    
        y += sign(vsp);    
    }    
    vsp = 0;     
}       
y += vsp;    

错误讯息:

___________________________________________
################################################################################    ############
FATAL ERROR in
action number 1
of  Step Event0
for object obj_player:

Variable obj_player.movespeed(100011, -2147483648) not set before reading it.
 at gml_Object_obj_player_StepNormalEvent_1 (line 8) - hsp = move * movespeed;
    ################################################################################    ############

这段代码有什么问题?我已经被困在它上几天了,真的很困惑,因为我看到这段代码在行动中以及在这段视频中的其他人https://www.youtube.com/watch?v=IysShLIaosk(在我最初的问题之后我添加了一些建议的变化:) {{ 3}}

2 个答案:

答案 0 :(得分:0)

这只是印刷错误。仔细查看Create事件,你写在那里&#34;移动 ps eed = 4;&#34;

答案 1 :(得分:0)

您在obj_players创建事件中错失了移动速度。