Hi there,
I need to use a continue command. When I started löve i was new to lua. I read that you can add the continue functionality to lua by external libs or something....
How can I integrate it?
Thanks
By the way: Is there a possibility of breaking out of 2 loops? Like in PHP break(2); ?
using continue
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: using continue
You might want to reconsider your code flow and such. If there's absolutely no other way to do it (such as iterating a two dimensional array, as happens a lot in gaming), you might want to consider the break command. I know it works in for / do loops. I don't know if it works in while / do or repeat / until loops.
EDIT:
To break two loops, you need to check a conditional and set break-points in each loop. For instance:
This is an arbitrary example, but basically in the nested loop, if a condition is met that needs to break the loop, then you set a local variable (scope is important, make the variable global if you need to know elsewhere in the program if a loop as been broken) to true and check it in the parent loop. Hope that makes sense.
EDIT:
To break two loops, you need to check a conditional and set break-points in each loop. For instance:
Code: Select all
function breakLoop()
local breakCondition
for y = 1 to 50 do
for x = 1 to 50 do
if x == 49 then
breakCondition = true
break
end
end
if breakCondition = true
break
end
end
end
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
- Star Crunch
- Prole
- Posts: 33
- Joined: Sun Feb 15, 2009 12:13 am
- Location: Monterrey, MX
- Contact:
Re: using continue
If you don't need to do a break, you can simulate a continue as follows:
Code: Select all
for i = 1, NumberOfThingsToIterate do -- OUTER LOOP
repeat -- "LOOP" to break out of in order to continue
if WantsToContinue() then
break -- "continue"
end
DoRegularStuff()
until false
end
Re: using continue
after some testing in core lua I retract my statement about while loops being faster than repeat until
- Star Crunch
- Prole
- Posts: 33
- Joined: Sun Feb 15, 2009 12:13 am
- Location: Monterrey, MX
- Contact:
Re: using continue
There was a reason for the repeat-until loop, but I messed up the example. It should read repeat until true... this "loops" once, but you can still break out, thereby faking the continue. If you don't break, it proceeds normally.
If you need to mix breaks and continues, though, this isn't the way to go.
External libs:
Metalua has continue:
http://metalua.luaforge.net/src/index.html#lib
If you're willing / able to customize Lua (for a Löve app, probably not), there are patches for continue and break N here:
http://lua-users.org/wiki/LuaPowerPatches
If you need to mix breaks and continues, though, this isn't the way to go.
External libs:
Metalua has continue:
http://metalua.luaforge.net/src/index.html#lib
If you're willing / able to customize Lua (for a Löve app, probably not), there are patches for continue and break N here:
http://lua-users.org/wiki/LuaPowerPatches
Re: using continue
How can I integrate the external lib in my LÖVE app?
I considered the other solutions myself but i think that shouldn't be the way!
I considered the other solutions myself but i think that shouldn't be the way!
- athanazio
- Citizen
- Posts: 96
- Joined: Fri Apr 10, 2009 3:12 am
- Location: Rio de Janeiro - Brazil
- Contact:
Re: using continue
@Sparx
I think I found how in the Lua documentation with the loadlib(), but it seems to be unable in LOVE,
take a look http://love2d.org/forum/viewtopic.php?f=3&t=665#p6288
I think I found how in the Lua documentation with the loadlib(), but it seems to be unable in LOVE,
take a look http://love2d.org/forum/viewtopic.php?f=3&t=665#p6288
Nothing is simple but everything is possible.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: using continue
@Sparx & anthanazio:
Check my post http://love2d.org/forum/viewtopic.php?f=3&t=665
More importantly if it's already a lib built for lua it's just following the docs for that lib. (most of them just tell you to use require)
You have to copy the distribution of that lib to your .love (may consist of .lua's and .dll's/.so's), require will search in the .love.
EDIT: Btw, I do want to mention I consider this somewhat bad practice.
Check my post http://love2d.org/forum/viewtopic.php?f=3&t=665
More importantly if it's already a lib built for lua it's just following the docs for that lib. (most of them just tell you to use require)
You have to copy the distribution of that lib to your .love (may consist of .lua's and .dll's/.so's), require will search in the .love.
EDIT: Btw, I do want to mention I consider this somewhat bad practice.
Re: using continue
I startet Lua 3 weeks ago. You can find your way arround continue and breaking out of more than 1 slope... BUT:
These things are sooo basic to me and I don't likke integrating an external lib just for a continue.... It should be somehow integrated into LÖVE....
These things are sooo basic to me and I don't likke integrating an external lib just for a continue.... It should be somehow integrated into LÖVE....
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests