Log In  

Maybe this is me being stupid, but no matter how I look at it I feel like my code should be working.
Button presses are working in the title screen and dialogue sections, but for some reason it stops working in the main gameplay. The code looks sound to me and everything else behaves as it should, debugging has shown me that the functions are indeed being called. But inputs just don't work. Here is where the offending code could be:

function init_battle()
t=0 --keeps track of time for bullet timing
pl_shot ={}
boss_shot={}
actor={}
player = {
x=60,
y=100,
life=3,
speed=2, 
focus=0,
life =3,
box ={
xa=0,
xb=2,
ya=0,
yb=2
}
}
boss = {
x=60,
y= 40,
life=100,
spell=1,
box = {
xa=0,
xb=3,
ya=0,
yb=3
}
} 

music(22)
_update=update_battle()
_draw=draw_battle()

end

function update_battle()
player_movement()
end

function player_movement()
    if (btn(0))then
player.x-=player.speed
    end 
if (btn(1)) then
player.x+=player.speed 
end
    if (btn(2)) then
player.y-=player.speed 
    end
if (btn(3)) then
player.y+=player.speed
end

end

function draw_battle()
cls()
map(0,0)
spr(1,player.x,player.y)
draw_hud()
end

function draw_hud()
spr(14,100,0)
    for i =108,124,8 do
    spr(15,i,0)
    end
    for i = 8,112,8 do
    spr(30,100,i)
    end
    spr(25,100,120)
    rectfill(108,8,128,125,13)
end

P#87312 2021-02-06 23:54 ( Edited 2021-02-07 02:47)

1

The problem is probably this bit here:

_update=update_battle()
_draw=draw_battle()

What you probably want is instead:

_update=update_battle
_draw=draw_battle

Reason being that you want to change _update/_draw to reference your two functions, but instead you are assigning to them the output of those functions, which will be nil.

P#87315 2021-02-07 01:28

@chrislewisdev
The parentheses were indeed the cause of my problem. Thank you very much!

P#87319 2021-02-07 02:46

[Please log in to post a comment]