Jump to content




Beginner in Lua and Table (?)


6 replies to this topic

#1 Neekow

  • Members
  • 55 posts

Posted 20 February 2013 - 04:56 AM

[Title] Beginner in Lua and Table (?).


NB: I'm french, and my english isn't perfect ... hope you will understand me ^^.

Hi everyone, i'm doing a digicode with touch screen, but i need a bit help to clean the code ^^.
Here's a screen of the final result:
Posted Image

and here's the code for that:
Spoiler


But, as you can see, the code is really ... disgusting? It work pretty fine but i wanna do better, if ever i wanna modify it later.

So i began an other code, trying to clean up this thing by using tables
Spoiler

But this time, no numbers appear =( (and haven't any error on screen ...). This is why i need some help to learn about table (if its table ^^), so ... please someone, tell me where i'm wrong =$

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 February 2013 - 05:48 AM

Split into new topic.

You never called fillTable, and you're using `for name, data in` and then referencing bData. There may be other issues, but those two would definitely prevent writing anything.

#3 Jan

  • Members
  • 141 posts
  • Locationthe Netherlands

Posted 20 February 2013 - 06:28 AM

View PostNeekow, on 20 February 2013 - 04:56 AM, said:

NB: I'm french, and my english isn't perfect ... hope you will understand me ^^.
(snip)
   print("perdu")

No problem, I've seen Mr Beans Holiday, so I know what perdu means ;)

I will take a look at your code.

#4 Jan

  • Members
  • 141 posts
  • Locationthe Netherlands

Posted 20 February 2013 - 07:13 AM

Here is an edited version.
see the comments to see what I changed

Spoiler
Maybe you can make the Pass() function smaller yourself?
Tip: use this to check if a number is even or odd:
if (number%2)==0 then
-- even
else
-- odd
end


#5 Doyle3694

  • Members
  • 815 posts

Posted 21 February 2013 - 06:03 AM

This piece of code:
for i = 1,5 do
   if i == 1 then m.setTextColor(colors.green) end
   if i == 2 then m.setTextColor(colors.lime) end
   if i == 3 then m.setTextColor(colors.green) end
   if i == 4 then m.setTextColor(colors.lime) end
   if i == 5 then m.setTextColor(colors.green) end
   m.setCursorPos(1,11)
   m.write("X")
   m.setCursorPos(3,11)
   m.write("X")
   m.setCursorPos(5,11)
   m.write("X")
   m.setCursorPos(7,11)
   m.write("X")
   sleep(0.5)
end
Can be changed too:
for i = 1,5 do
   if i%2 == 1 then m.setTextColor(colors.green)
   elseif i%2 == 0 then m.setTextColor(colors.lime) end
   for i = 1,7,2 do
	  m.setCursorPos(i,11)
	  m.write("X")
	  sleep(0.5)
   end
end


#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 21 February 2013 - 07:30 AM

View PostDoyle3694, on 21 February 2013 - 06:03 AM, said:

This piece of code:
--snip
Can be changed too:
for i = 1,5 do
   if i%2 == 1 then m.setTextColor(colors.green)
   elseif i%2 == 0 then m.setTextColor(colors.lime) end
   for i = 1,7,2 do
	  m.setCursorPos(i,11)
	  m.write("X")
	  sleep(0.5)
   end
end

And that can be changed to
for i = 1,5 do
	m.setTextColor( i%2 == 1 and colors.green or colors.lime )
	for i = 1,7,2 do
		m.setCursorPos(i,11)
		m.write("X")
		sleep(0.5)
	end
end

^^

#7 Neekow

  • Members
  • 55 posts

Posted 28 February 2013 - 01:10 PM

Thanks for help, now i think i understood the table and i'll rewrite (at least try) it. i'll post when it's done ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users