This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Agoldfish's profile picture

Weird Error I Have Never Gotten Before

Started by Agoldfish, 28 October 2013 - 08:56 AM
Agoldfish #1
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
Lyqyd #2
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.
Zudo #3
Posted 28 October 2013 - 10:24 AM
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", ...}
Agoldfish #4
Posted 28 October 2013 - 11:14 AM
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))
Lyqyd #5
Posted 28 October 2013 - 01:48 PM
No, myTable[2]
Agoldfish #6
Posted 28 October 2013 - 03:54 PM
No, myTable[2]
So…
print(myTable[2])
Lyqyd #7
Posted 28 October 2013 - 04:20 PM
That's how you would print it, sure.
awsmazinggenius #8
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.