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

Help Coding - Creating CC Arcade Games (Card Swipe with Immibis Per.)

Started by black_hawk143, 12 April 2015 - 04:05 PM
black_hawk143 #1
Posted 12 April 2015 - 06:05 PM
I did check the FAQ "diagnostics" page, and didn't find any solutions to the errors (mainly because ether A. The error was not listed B. I could not understand the definition). Yes, I did also check Immibis' page, and my code was all right there.
Hello, I'm trying to make a arcade game where you swipe a Immibis Peripherals mag-card on a reader to play.
I'm still figuring out how to put together my own code (It took my 3 hours to complete the one below. :blink:/>/> )
I do suspect I will be referring to this post for help multiple times! :)/>/>

I don't get what the problem is with this one…
I have 1 mag-card reader, 1 adv. monitor, 1 adv. computer, hooked together with networking cables and wired modems. the wired modems do have the red band. Oh, and I'm running this on a disk.

What should happen is it displays "Your balance is: " the whole time accept when rebooting.
So the reader will be waiting for a swiped card. (Event: "mag_swipe") then it will display the value of the card below the
text, and after 5-6 seconds it will reboot (I set the startup to be this program). The code "os.reboot()" doesn't work in my case, so I put the waiting for read event into a function, so a reboot is just restarting the function.



Spoiler


[color=#00ffff]Code[/color]:

Resulting Error: bal:12 attempt to index ? (a nil value)

 ready = true
 m = peripheral.wrap("monitor_1")

 m.clear()
 m.setCursorPos(1,1)
 m.setTextScale(0.8) 
 m.setTextColor(colors.white)
 m.write("You Balance is:")
 m.setCursorPos(1,3)

 while true do
 reader.setInputCardLight(true)
 p1,p2,p3 = os.pullEvent("mag_swipe")
 m.write("Points: "..p2)
 end 
 
 sleep(5)
 m.clear()
 m.setCursorPos(1,1)
Edited on 13 April 2015 - 01:46 AM
Bomb Bloke #2
Posted 12 April 2015 - 11:43 PM
I did check the FAQ "diagnostics" page, and didn't find any solutions to the errors (mainly because ether A. The error was not listed B. I could not understand the definition).

Speaking of which, you forgot to mention what error you were getting, or to otherwise describe what this script currently does currently do.

At a quick glance, you've defined three functions, but at no point outside these function definitions do you attempt to call them. They'd therefore sit there doing nothing.

Also, it appears that "run()" calls "boot()" and "boot()" calls "run()". That'll lead to a crash, because Lua has to track every function call you make until they complete. If none of your functions are ending, but are instead just making more and more function calls, it'll eventually run out of memory to store the function stack and crash as a result. If you want to repeat code indefinitely, use a "while true do" loop.

(How do you do the spoiler drop down box?)

Wrap your code in spoiler (and, because it's code, code) tags:

[spoiler][code]Code goes here[/code][/spoiler]
black_hawk143 #3
Posted 13 April 2015 - 12:11 AM
Ok, new design

Spoiler
 ready = true
[font=courier new,courier,monospace] m = peripheral.wrap("monitor_1")[/font]

[font=courier new,courier,monospace] m.clear()[/font]
[font=courier new,courier,monospace] m.setCursorPos(1,1)[/font]
[font=courier new,courier,monospace] m.setTextScale(0.8) [/font]
[font=courier new,courier,monospace] m.setTextColor(colors.white)[/font]
[font=courier new,courier,monospace] m.write("You Balance is:")[/font]
[font=courier new,courier,monospace] m.setCursorPos(1,3)[/font]

[font=courier new,courier,monospace] reader.setInputCardLight(true)[/font]
[font=courier new,courier,monospace] p1,p2,p3 = os.pullEvent("mag_swipe")[/font]
[font=courier new,courier,monospace] m.write("Points: "..p2)[/font]

[font=courier new,courier,monospace] sleep(5)[/font]
[font=courier new,courier,monospace] m.clear()[/font]
[font=courier new,courier,monospace] m.setCursorPos(1,1)[/font]

Error Msg:
bal:11 attempt to index ? (a nil value)
black_hawk143 #4
Posted 13 April 2015 - 12:40 AM
Ok,

The error is bal:12 attempt to index ? (a nil value)

Spoiler

[font=courier new,courier,monospace] ready = true[/font]
[font=courier new,courier,monospace] m = peripheral.wrap("monitor_1")[/font]

[font=courier new,courier,monospace] m.clear()[/font]
[font=courier new,courier,monospace] m.setCursorPos(1,1)[/font]
[font=courier new,courier,monospace] m.setTextScale(0.8) [/font]
[font=courier new,courier,monospace] m.setTextColor(colors.white)[/font]
[font=courier new,courier,monospace] m.write("You Balance is:")[/font]
[font=courier new,courier,monospace] m.setCursorPos(1,3)[/font]

[font=courier new,courier,monospace] while true do[/font]
[font=courier new,courier,monospace] reader.setInputCardLight(true)[/font]
[font=courier new,courier,monospace] p1,p2,p3 = os.pullEvent("mag_swipe")[/font]
[font=courier new,courier,monospace] m.write("Points: "..p2)[/font]
[font=courier new,courier,monospace] end [/font]

[font=courier new,courier,monospace] sleep(5)[/font]
[font=courier new,courier,monospace] m.clear()[/font]
[font=courier new,courier,monospace] m.setCursorPos(1,1)[/font]
flaghacker #5
Posted 13 April 2015 - 08:41 AM
You never assign the variable "reader". I assume you want to wrap the reader as a peripheral.


reader = peripheral.wrap ("right") --if you know the side or exact peripheral name
reader = peripheral.find ("reader") --if you want to find the reader, eg. on a wired network

I don't know the exact peripheral id of the reader, change the "reader" to the correct id.
Edited on 13 April 2015 - 06:42 AM
black_hawk143 #6
Posted 14 April 2015 - 12:40 AM
You never assign the variable "reader". I assume you want to wrap the reader as a peripheral.

reader = peripheral.wrap ("right") if you know the side or exact peripheral name
reader
= peripheral.find ("reader") if you want to find the reader, eg. on a wired network

I don't know the exact peripheral id of the reader, change the "reader" to the correct id.

New code… Error: bal:14 attempt to index ? (a nil value)

Spoiler

 ready = true
 m = peripheral.wrap("monitor_1")
 r = peripheral.find("reader_0")
 r = peripheral.wrap("reader_0")

 m.clear()
 m.setCursorPos(1,1)
 m.setTextScale(0.8) 
 m.setTextColor(colors.white)
 m.write("You Balance is:")
 m.setCursorPos(1,3)

 while true do
 r.setInputCardLight(true)
 p1,p2,p3 = os.pullEvent("mag_swipe")
 m.write("Points: "..p2)
 end 

 sleep(5)
 m.clear()
 m.setCursorPos(1,1)
Edited on 13 April 2015 - 10:42 PM
Bomb Bloke #7
Posted 14 April 2015 - 12:45 AM
It's telling you that you're trying to reference something inside a table, but there's no table to index into. You're trying to index into nothing.

On that line, you're doing:

r.setInputCardLight(true)

So "r" is the table you're trying to index into. It's saying "r" is nil.

You last attempted to set "r" to something on line four:

r = peripheral.wrap("reader_0")

So essentially the error boils down to "your attempt to wrap reader_0 failed". Make sure your script actually has access to such a peripheral.

Really it looks like you want to just replace lines three and four with:

r = peripheral.find("reader")

That should work so long as the script has access to any peripheral with the type of "reader".
black_hawk143 #8
Posted 14 April 2015 - 01:57 AM
Good News!
Problem 01 is solved.

This is the first code that I wrote. :D/>

Working Script:
Spoiler

 ready = true
 m = peripheral.wrap("monitor_1")
 reader = peripheral.wrap("right")

 function boot()
 reader.setInsertCardLight(false)
 sleep(5)
 m.clear()
 m.setCursorPos(1,1)
 os.reboot()
 end

 m.clear()
 m.setCursorPos(1,1)
 m.setTextScale(0.8) 
 m.setTextColor(colors.white)
 m.write("You Balance is:")
 m.setCursorPos(1,3)

 while true do
 reader.setInsertCardLight(true)
 p1,p2,p3 = os.pullEvent("mag_swipe")
 m.write("Points: "..p2)
 boot()
 end 

To run this, put a monitor down and connect it via network cable, then edit wrap in code
Set computer, then on right a Immibis mag card reader, and under it a floppy reader and put a disk in and put this code on it.
then on the computer, edit "startup" and put

shell.run("disk/bal")
black_hawk143 #9
Posted 14 April 2015 - 04:18 AM
Code Problem #2:

I'm working on the register program for the arcade.
What it's supposed to do is (when it starts) show a list saying 1 add money to the mag card or 2 redeem points (I haven't figured out that one yet so that function is blank)

Resulting Error: reg:9 expected number
But I don't know which line.

Code:
Spoiler

--Peripherals & Functions--
m = peripheral.wrap("right")
r = peripheral.wrap("left")

function wel()
text = "Welcome to FunPlanet Arcade"
m.setCursorPos(2,3)
m.setTextColor(colors.gold)
m.setTextScale(0.8)
m.write(text)
end

function menu2()
m.clear()
m.setCursorPos(1,1)
m.setTextColor(colors.green)
term.clear()
term.setCursorPos(1,1)
term.write("Amount to add: ")
amt = read()
name = "FunPlanet Arcade Card"
r.beginWrite(amt,name)
end

function menu3()
-- not coded yet
end

--Start Code--

m.clear()
wel()
term.clear()
term.setCursorPos(1,1)

print("1 : Add cash to card")
print("2 : Redeem prizes")

input = read()

if input == "1" then
  m.clear()
  m.write("Add money to card.")
  sleep(0.7)
  menu2()
elseif input == "2" then
  m.clear()
  m.write("Redeem points!")
  sleep(.7)
  menu3()
end
Edited on 14 April 2015 - 02:21 AM
Bomb Bloke #10
Posted 14 April 2015 - 04:31 AM
The number in the error - 9 - indicates the line. You appear to be posting a slightly different version of the code to that which produced the error, however, as what you've got here will fail on line 8 - because "colors.gold" isn't a number (it's not defined at all, so it's nil), m.setTextColor() can't accept it.
black_hawk143 #11
Posted 15 April 2015 - 04:30 AM
Code Problem #2.1

For the register
I have a separate computer running the below code.

It's supposed to display on one of the sceens (screen one = reg 1)
Welcome to FunCade, Lane is open
when a lever is on. (It's connected via Project Red Bundled cable)
and when the lever is off it displays
Lane Closed

Resulting Error: lane:9 too long without yielding
I know what this means, just how do prevent it?

Spoiler

color1 = rs.getBundledInput("top")
color2 = rs.getBundledInput("back")
m1 = peripheral.wrap("monitor_2")
m2 = peripheral.wrap("monitor_3")

–Code Start–

while true do
start1 = rs.testBundledInput("top",color1)
start2 = rs.testBundledInput("back",color2)
end

–Register 1–
if start1 == true then
while true do
m1.clear()
m1.setBackgroundColor(16)
m1.setTextColor(2048)
m1.setTextScale(1.5)
m1.clear()
m1.setCursorPos(1,1)
m1.write("Welcome to FunCade,")
m1.setCursorPos(1,2)
m1.write("Redeem Tickets Here.")

sleep(3)

m1.clear()
m1.setCursorPos(1,1)
m1.setTextScale(2)
m1.setTextColor(16384)
m1.write("Lane 1 Open")

sleep(2)
end
end

if start1 == false then
m1.clear()
m1.setCursorPos(1,1)
m1.setTextColor(16384)
m1.setTextScale(1.5)
m1.write("Lane Closed.")
end
–Register 2–
if start2 == true then
while true do
m2.clear()
m2.setBackgroundColor(16)
m2.setTextColor(2048)
m2.setTextScale(1.5)
m2.clear()
m2.setCursorPos(1,1)
m2.write("Welcome to FunCade,")
m2.setCursorPos(1,2)
m2.write("Redeem Tickets Here.")

sleep(3)

m2.clear()
m2.setCursorPos(1,1)
m2.setTextScale(2)
m2.setTextColor(16384)
m2.write("Lane 2 Open")

sleep(2)
end
end

if start2 == false then
m2.clear()
m2.setCursorPos(1,1)
m2.setTextColor(16384)
m2.setTextScale(1.5)
m2.write("Lane Closed.")
end
Bomb Bloke #12
Posted 15 April 2015 - 07:34 AM
You need to re-arrange those "while" loops. Currently, your script is getting caught in this block:

while true do                           -- Start a loop that repeats indefinitely.
  start1 = rs.testBundledInput("top",color1)  -- Assign a variable.
  start2 = rs.testBundledInput("back",color2) -- Assign another variable.
end                                           -- Go back to the top of the loop and repeat the above.

The rest of your script will never run, because these are the only two lines in your never-ending loop. Perhaps try moving that particular end a bit lower down?