Jump to content




[Question] How Do We Use Table.insert And Table.remove Correctly?


  • You cannot reply to this topic
4 replies to this topic

#1 crackroach

  • Members
  • 62 posts
  • LocationSomewhere over the rainbow

Posted 25 August 2013 - 05:32 PM

So, the title explain it i guess, but here's why i came with this question: I am currently making a touchscreen password(yup another <_<).

--That's just for information


key = {}
  key.digit = {}
	key.digit[1] = {1; x; y}
	key.digit[2] = {2; (x * 2); y}
	key.digit[3] = {3; (x * 3); y}
	key.digit[4] = {4; x; (y * 2)}
	key.digit[5] = {5; (x * 2); (y * 2)}
	key.digit[6] = {6; (x * 3); (y * 2)}
	key.digit[7] = {7; x; (y * 3)}
	key.digit[8] = {8; (x * 2); (y * 3)}
	key.digit[9] = {9; (x * 3); (y * 3)}


-- Check for the mouse click position
local function checkPosition(btn, nmb)
  b = 1
  for a = 1, 9 do
	if mouseW == key.digit[b][2] and mouseH == key.digit[b][3] and btn == 1 then
	  mon.write("key pressed"..key.digit[b][1])
	  table.insert(password, key.digit[b][1])
	  mon.write("pass :"..tostring(password[nmb]))
   end
  b = b + 1
end
end

I am using it correctly?

If you need the rest of the code just tell me and i'll post it

Thx Crackroach

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 25 August 2013 - 08:53 PM

Reverse the variables in the function. The table you want to insert into is the first argument and the thing you're inserting is the second argument.

local sometable = {}
table.insert(sometable, "Index1")
table.remove(sometable, 1)
print(#sometable) --# Outputs 0


#3 Kilobyte

  • Members
  • 122 posts

Posted 26 August 2013 - 11:47 AM

You can also specify an index to third argument. Then it will insert at that index and not the end.

#4 crackroach

  • Members
  • 62 posts
  • LocationSomewhere over the rainbow

Posted 29 August 2013 - 03:34 PM

Ok thanks to both of you.

#5 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 29 August 2013 - 04:17 PM

key={
digit={
{1,x,y},
{2,x*2,y},
{3,x*3,y},
{4,x,y*2},
{5,x*2,y*2},
{6,x*3,y*2},
{7,x,y*3},
{8,x*2,y*3},
{9,x*3,y*3},
}
}
you might also want to form tables like this





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users