Jump to content




Weird Error I Have Never Gotten Before


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

#1 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 28 October 2013 - 09:56 AM

Hi, I was writing my weird horse race simulator and I came across this while simulating....
For input string: "1horse"
I tried spacing some stuff and ends etc... I just can't figure it out.
Here is my code... I figured out how to get it from CCDesk
--VARIABLES AND FUNCTIONS--
local randomize = math.random(1,6)
local 1horse = "Gitty Bomb"
local 2horse = "Sleeper"
local 3horse = "Outside Charge"
local 4horse = "From the back"
local 5horse = "Take Charge South Man!"
local 6horse = "A New Life"
---------------------------------------
function clearScreen()
term.clear()
term.setCursorPos(1, 1)
end
--PROGRAM START--
print"And... They're off!"
sleep(2)
clearScreen()
print(1horse)

Please help!

-Agoldfish

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 October 2013 - 09:59 AM

Variable names can't start with numbers.

You really should be creating a table of horse names anyway.

#3 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 28 October 2013 - 10:24 AM

View PostLyqyd, on 28 October 2013 - 09:59 AM, said:

Variable names can't start with numbers.

You really should be creating a table of horse names anyway.

To make a table, use this:

local myTable = {"item1", "item2", ...}


#4 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 28 October 2013 - 11:14 AM

View PostZudoHackz, on 28 October 2013 - 10:24 AM, said:

View PostLyqyd, on 28 October 2013 - 09:59 AM, said:

Variable names can't start with numbers.

You really should be creating a table of horse names anyway.

To make a table, use this:

local myTable = {"item1", "item2", ...}
To reference item2 in the table do..?
print(myTable(2))


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 October 2013 - 01:48 PM

No, myTable[2]

#6 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 28 October 2013 - 03:54 PM

View PostLyqyd, on 28 October 2013 - 01:48 PM, said:

No, myTable[2]
So...
print(myTable[2])


#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 October 2013 - 04:20 PM

That's how you would print it, sure.

#8 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 31 October 2013 - 05:52 PM

If, like me, you hate tables, you can use horse1, horse2 instead of 1horse, 2horse to do it, but for large sets of data it's best to use tables. This probably isn't the most efficient way to do it, but you could do this:
horses = {}
horses[1] = 3.00  --# time or something. I don't know what you want to do with this program
horses[2] = 5.00
print(horses[1])
print(horses[2])

if condition == true then
  horses[2] = 4.04
end

I am quite nooby with tables however. Just an example of how to use them. If you want further help tell us what the program is for.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users