Thanks so much I promise to actually study the language when I finished high school
So just making this clear, for an IF statement, if the process of its insides results in the condition being contradicted, execution will continue all the way to the end of the IF statement and only then can it exit?
How to handle collision resolutions?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to make a Wait function? :s
Not sure what you mean by this. Could you give an example?onedaysnotice wrote:So just making this clear, for an IF statement, if the process of its insides results in the condition being contradicted, execution will continue all the way to the end of the IF statement and only then can it exit?
Help us help you: attach a .love.
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: How to make a Wait function? :s
Like even for thisRobin wrote:Not sure what you mean by this. Could you give an example?
Code: Select all
function time:update(dt)
if self.waiting then
self.elapsed = self.elapsed + dt
if self.elapsed >= self.total then
self.elapsed = 0
self.waiting = false
return true -- NOT "return true end", that makes no sense
-- also notice you need to return AFTER you reset those properties, not before
end
end
end
So from what I've gathered here is that if execution is within an IF statement and while inside, if the IF statement's conditions are not met, execution will still continue until the end of the IF statement and then only then can it exit. This is as opposed to if the conditions are not met, execution will immediately exit the IF statement regardless of whether there is any processes after it, as if there was a Break statement there. Is this correct?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to make a Wait function? :s
Maybe it helps to look at it like this:
This:
Is really this: (not valid Lua, just to give you an idea how it works under the hood)
You see, once you pass the first check, the code does no further checks.
This:
Code: Select all
if self.elapsed >= self.total then
self.elapsed = 0
self.waiting = false
return true
end
Code: Select all
if not (self.elapsed >= self.total) jump to label1
self.elapsed = 0
self.waiting = false
return true
label1
Help us help you: attach a .love.
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
How to make a Wait function? :s again. lol
Oh i see. That makes things much clearer. Thanks
---
Oh, and btw, my wait function is not working entirely as I want it to I've done some slight changes to what you gave me, but it still doesn't work right.
If I make the condition of an if statement for the wait function to be false, like:
it works perfectly fine. However, if i make the condition for it to be true, it doesn't work. Like:
What needs to be changed so that true conditions would work as well? :s
---
Oh, and btw, my wait function is not working entirely as I want it to I've done some slight changes to what you gave me, but it still doesn't work right.
Code: Select all
local time = {}
time.__index = time
function newWait(seconds)
local t = setmetatable({}, time)
t.elapsed = 0
t.total = seconds
t.waiting = false
t.finished = false
return t
end
function time:update(dt)
if self.waiting then
self.elapsed = self.elapsed + dt
if self.elapsed >= self.total then
self.elapsed = 0
self.waiting = false
self.finished = true
return true
end
end
end
function time:reset()
self.elapsed = 0
self.finished = false
end
function time:wait()
self.elapsed = 0
self.finished = false
self.waiting = true
end
function time:waitFinished()
return self.finished
end
Code: Select all
quartersec:update(dt) ==> (i just put this line somewhere around the top of my love.update() function)
...
quartersec:wait()
if not quartersec:waitFinished() then
...
end
Code: Select all
if quartersec:waitFinished() then
...
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to make a Wait function? :s again lol.
- In the future, please always upload a .love of what you're doing. This makes things much easier for everyone involved.
- First, you call quartersec:wait(). There quartersec.finished is set to false. Then, quartersec:waitFinished() returns quartersec.finished, which you just established is false. Thus, it always returns false and never executes the then branch.
Solution: remove the call to quartersec:wait() and place it where the timer should start.
Help us help you: attach a .love.
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: How to make a Wait function? :s again lol.
Sorry for the late response. I was at a skiing trip with family and friends. I'll make sure to upload a .love next timeRobin wrote:
- In the future, please always upload a .love of what you're doing. This makes things much easier for everyone involved.
- First, you call quartersec:wait(). There quartersec.finished is set to false. Then, quartersec:waitFinished() returns quartersec.finished, which you just established is false. Thus, it always returns false and never executes the then branch.
Solution: remove the call to quartersec:wait() and place it where the timer should start.
Whilst offline coding at the trip during free time, I decided to scrap the wait function idea and stick with the fundamentals that I know. Better to have an unoptimised working product than a half-baked, minutely perceivably optimised, dysfunctional product lol, since the project is due the week after next. Damn me and my severe procrastination Dx.
Thanks for the continued help though, Robin.
-----------------------------
Issue #4 - How to handle collision resolution?
STATUS: Unresolved.
I'm just sticking to box collision for now, so the detection part is completely fine. However, the resolution part is what is causing me grief. Right now, I have resolved most my problems with the collision resolution. There is still a multitude of problems however, namely the teleporting when jumping towards the opponent when already touching them. There is also the occasional issue where the player will get stuck on the opponent's top right/left corner and both will move in a uniform direction and speed. Oh there's also the one about jumping on a person thats next to the wall, so it makes the pushing of the top char not occur, but I plan on working on it right now.
I know my code is incredibly hideous, but can you guys please look into what is causing the other glitches? Well I understand why its happening, but I don't really have an idea as to how to go about to solving them. Is there a simpler way of tackling this collision resolution whilst still providing the same functionalities, without the use of libraries because I'm really trying to minimise my use of them, at least for this project. Thanks.
wasd to move player 1, arrow keys to move player 2.
- Attachments
-
- Archive.love
- (5.55 KiB) Downloaded 107 times
Who is online
Users browsing this forum: Amazon [Bot], Google [Bot] and 17 guests