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
How to handle collision resolutions?
||===========onedaysnotice help thread============||
**I moved the thread to this board since its more appropriate **
Before i infuriate the whole love2d community with my incessant making of 'help me' and 'how to' threads, I've decided to create a centralised thread xD
Current problem: viewtopic.php?p=60456#p60456
------------------------------------------------------------------------------------------------------------
Issue #1
--------------------------------
STATUS: resolved.
if you remove elements of a table using table.remove(), does the next existing element become index 1, or does it remain the same index and new elements will just replace the empty indexes?
like if I have a table:
a = {}
a[1] = 4
a[2] = 2
a[3] = 7
if I remove a[1] and a[2], does a[3] become index 1 afterwards?
thanks Sorry for the noob question xD.
**I moved the thread to this board since its more appropriate **
Before i infuriate the whole love2d community with my incessant making of 'help me' and 'how to' threads, I've decided to create a centralised thread xD
Current problem: viewtopic.php?p=60456#p60456
------------------------------------------------------------------------------------------------------------
Issue #1
--------------------------------
STATUS: resolved.
if you remove elements of a table using table.remove(), does the next existing element become index 1, or does it remain the same index and new elements will just replace the empty indexes?
like if I have a table:
a = {}
a[1] = 4
a[2] = 2
a[3] = 7
if I remove a[1] and a[2], does a[3] become index 1 afterwards?
thanks Sorry for the noob question xD.
Last edited by onedaysnotice on Sun Jul 08, 2012 1:08 pm, edited 15 times in total.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: table.remove question
http://codepad.org/dd5AWIeTonedaysnotice wrote:if I remove a[1] and a[2], does a[3] become index 1 afterwards?
Code: Select all
sample = {"hello", "felicia", "day"}
print(sample[1])
table.remove(sample,1)
table.remove(sample,1)
print(sample[1])
Code: Select all
hello
day
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: table.remove question
ok good. thanksTechnoCat wrote:http://codepad.org/dd5AWIeTonedaysnotice wrote:if I remove a[1] and a[2], does a[3] become index 1 afterwards?
Code: Select all
sample = {"hello", "felicia", "day"} print(sample[1]) table.remove(sample,1) table.remove(sample,1) print(sample[1])
Code: Select all
hello day
finally had the sense to check the tables library tutorial at:
http://lua-users.org/wiki/TableLibraryTutorial
and it clearly states "The remaining elements are reindexed sequentially and the size of the table is updated to reflect the change."
*facepalm*. Sorry for the stupid questions guys :S.
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Issue #2
STATUS: resolved.
How can you print the value of input_time in this table?
I've tried:
and
but all of them have either gotten nil error, or just printed the table id in terminal. :S
How can you print the value of input_time in this table?
Code: Select all
table.insert(box[i].keyCompare, {input_time = hidden_timer})
Code: Select all
for i = 1,2 do
if #box[i].keyCompare.input_time > 0 then
table.foreachi(box[i].keyCompare.input_time, print)
end
end
Code: Select all
for i = 1,2 do
if #box[i].keyCompare.inputTimer > 0 then
love.graphics.print(box[i].keyCompare.inputTimer[1], 100, 170)
if #box[i].keyCompare.inputTimer > 1 then
love.graphics.print(box[i].keyCompare.inputTimer[2], 100, 170)
end
end
end
Code: Select all
for j = 1,2 do
for i,v in ipairs(box[j].keyCompare.input_time) do
love.graphics.print(v.keyCompare.input_time, 100, 170)
end
end
- Attachments
-
- Archive.love
- I've commented out my tries
- (1.73 KiB) Downloaded 228 times
Last edited by onedaysnotice on Wed Jul 04, 2012 7:34 am, edited 3 times in total.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: how to print the values inside a sub, sub, sub table? lo
You shouldn't use table.foreach, btw, that's deprecated.
If you check your table.insert you can see you're inserting into box.keyCompare, so that's what you should be interating over.
Code: Select all
for i, v in ipairs(box[i].keyCompare) do
print(v.input_time)
end
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: how to print the values inside a sub, sub, sub table? lo
bartbes wrote:You shouldn't use table.foreach, btw, that's deprecated.
If you check your table.insert you can see you're inserting into box.keyCompare, so that's what you should be interating over.Code: Select all
for i, v in ipairs(box[i].keyCompare) do print(v.input_time) end
I tried plugging that in, but it just gets the nil value error as well :S
Re: how to print the values inside a sub, sub, sub table? lo
Try this one. It uses a "table to string" to show what happens when you press keys. Do you realy need a table for input_time?
- Attachments
-
- ArchiveX.love
- with (tabel)tostring
- (2.41 KiB) Downloaded 231 times
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: how to print the values inside a sub, sub, sub table? lo
Oh yay That works perfectly Thanks so much!Zeliarden wrote:Try this one. It uses a "table to string" to show what happens when you press keys. Do you realy need a table for input_time?
and ummm...I probably don't need to but...idk xD
hrmm to continue with this version or my new simplified one...
EDIT: Now that I can see the values of the input_time, it looks like keyCompare is not doing what I want it to. So I guess I might as well just stick to my simplified version.
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Issue #3 - How to make a wait function?
STATUS: Scrapped.
I am trying to make a wait function in an external file that outputs false until the specified time, at which it becomes true. I want it to be easily integrateable to any part of any code. I am almost certain that there is a much, much easier way of doing this but this is what I've got so far. (Hint: It doesn't work xD)
I have no idea what most of the code means btw, I was just tailoring Bartbes' AnAL code to suit this function lmao.
Can you please tell me how to change the code so that it works, or an easier method of solving this issue?
I am trying to make a wait function in an external file that outputs false until the specified time, at which it becomes true. I want it to be easily integrateable to any part of any code. I am almost certain that there is a much, much easier way of doing this but this is what I've got so far. (Hint: It doesn't work xD)
Code: Select all
local time = {}
time.__index = time
function newWait(seconds)
local t = {}
t.elapsed = 0
t.total = seconds
t.waiting = false
end
function time:update(dt)
if self.waiting then
self.elapsed = self.elapsed + dt
if self.elapsed >= self.total then
return true end
self.elapsed = 0
self.waiting = false
end
end
end
function time:reset()
self.elapsed = 0
end
function time:wait()
self:reset()
self.waiting = true
end
Can you please tell me how to change the code so that it works, or an easier method of solving this issue?
Last edited by onedaysnotice on Sun Jul 08, 2012 1:09 pm, edited 1 time in total.
- 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
First:
Fun fact, you can make the above one line:
Secondly, time.update should be different:
Code: Select all
function newWait(seconds)
local t = setmetatable({}, time) -- you need to set the metatable of t to time
t.elapsed = 0
t.total = seconds
t.waiting = false
return t -- if you don't return the table, you can't use it
end
Code: Select all
function newWait(seconds)
return setmetatable({elapsed = 0, total = seconds, waiting = false}, time)
end
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
Help us help you: attach a .love.
Who is online
Users browsing this forum: No registered users and 5 guests