Delay on a loop?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Findo777
Prole
Posts: 36
Joined: Tue Feb 25, 2014 4:09 am

Re: Delay on a loop?

Post by Findo777 »

Oh... thanks>:D


I tried implementing dt checking into my code, but unfortunately.... it does not do anything now,
It showed the last image before.. now it shows nothing.


This is in tank.lua (I used require"")

space_pressed = false
bullet = love.graphics.newImage("Images/bullet.png")
exp1 = love.graphics.newImage("Images/exp1.png")
exp2 = love.graphics.newImage("Images/exp2.png")
exp3 = love.graphics.newImage("Images/exp3.png")
less = 200
wait = 1
waiter = 1
debounce = true
state = 'nothing'

function love.update(dt)
if state == 'nothing' then
state = 'waiting'
timer = 0.08
end
if state == 'waiting' then
timer = timer - dt
end
if timer <= 0 then
state = 'nothing'
end
end


function attack()
debounce = false
bulletxpos = xpos
bulletypos = ypos
love.graphics.setColor(255,255,255)
if state == 'nothing' then
state = 'waiting'
Bullet = love.graphics.draw(bullet,bulletxpos,bulletypos)
repeat bulletpos = bulletpos - 1 until bulletpos == xpos - less
end
if state == 'nothing' then
state = 'waiting'
EXP1 = love.graphics.draw(exp1,bulletxpos,bulletypos - less)
end
if state == 'nothing' then
state = 'waiting'
EXP2 = love.graphics.draw(exp2,bulletxpos,bulletypos - less)
end
if state == 'nothing' then
state = 'waiting'
EXP3 = love.graphics.draw(exp3,bulletxpos,bulletypos - less)
space_pressed = false
debounce = true
end
end


This is ithe part of main.lua where it does attack function

function love.draw()
if space_pressed == true and debounce == true then
attack()
end


Help please :(
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: Delay on a loop?

Post by Wojak »

1) You should post a love file or post a full code in any other way
2) When posting a code on the forum use the 'code' tag
3) use the space or tab to highlight the scopes like here: http://love2d.org/forums/viewtopic.php?p=163955#p163955

In other words: “Help us to help You”

the possible problems:
1) missing end (but you likely did not copy it correctly)
2) if you have GLOBAL functions with the SAME NAME in tank.lua and main.lua and you use the require at the beginning of main lua, then the functions in main.lua will overwrite the ones in tank.lua
3) lets say that timer is 0 or less and the state is 'waiting':
the state will be set to 'nothing'
love.draw is always called after love.update do attack() will also be called after love update
if state is 'nothing' then attack() will always set it to 'waiting' but timer will not change
in the next frame the state is still 'waiting' and the timer will not reset...
removing state = 'waiting' from attack() should fix it...
Findo777
Prole
Posts: 36
Joined: Tue Feb 25, 2014 4:09 am

Re: Delay on a loop?

Post by Findo777 »

Thank you, I have removed that, but unfortunately, it still is not working.
Might I ask how to attach a .love?
Thank you....
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Delay on a loop?

Post by Robin »

How to make a .love: ZIP the contents of your game folder (not the folder itself, its contents!). Then rename mygame.zip to mygame.love.

How to attach it: when you make a post on the forums, below the post-entering-field, there is a tab that says "Upload attachment". Click it. Click "browse", open your .love file, click "Add the file", and submit your post.
Help us help you: attach a .love.
Findo777
Prole
Posts: 36
Joined: Tue Feb 25, 2014 4:09 am

Re: Delay on a loop?

Post by Findo777 »

Hello
I hope you see my attachments below....
Attachments
main.lua
Uh here.
(2.08 KiB) Downloaded 128 times
tank.lua
Rename this to .zip?
(1.48 KiB) Downloaded 133 times
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: Delay on a loop?

Post by Wojak »

You should check out this article:
http://www.love2d.org/wiki/Game_Distribution
Alternatively you can open any .love file with an archiving application, remove the content add replace it with the files and folders from Your project folder

Also a blue screen is not 'nothing' but an error! You should learn what each error massage means, and if you don't know post the massage on the forum (VERY INPORTANT if you relay want to receive any useful help)

Learn to format the code – if you do it correctly – things like missing or misplaced end will be easy to spot (the example how to format the code is in the attachment)

And finally You should describe what the code should be doing (What are You trying to make?)

the attachment should run, but it likely wont work as You want (I don't know what You want), it is also commented (what in My opinion was wrong).
Attachments
aTankGame.love
(25.07 KiB) Downloaded 132 times
Findo777
Prole
Posts: 36
Joined: Tue Feb 25, 2014 4:09 am

Re: Delay on a loop?

Post by Findo777 »

I want the bullet animations to slow down, instead of zooming through them until you cannot see.
Also, I do not see what your game changed except the tank pic.
Findo777
Prole
Posts: 36
Joined: Tue Feb 25, 2014 4:09 am

Re: Delay on a loop?

Post by Findo777 »

Also, in your game, I do not see any shooting animations
I see you made pictures for it... but it is not there.... perhaps something went wrong?
Findo777
Prole
Posts: 36
Joined: Tue Feb 25, 2014 4:09 am

Re: Delay on a loop?

Post by Findo777 »

It waiting works great now! Thanks for all ur guy's help! :D
Post Reply

Who is online

Users browsing this forum: No registered users and 164 guests