Jump to content




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

game peripheral help

11 replies to this topic

#1 black_hawk143

  • Members
  • 7 posts

Posted 12 April 2015 - 05: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

Edited by black_hawk143, 13 April 2015 - 02:46 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 12 April 2015 - 10:43 PM

View Postblack_hawk143, on 12 April 2015 - 05:05 PM, said:

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.

View Postblack_hawk143, on 12 April 2015 - 05:05 PM, said:

(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]

#3 black_hawk143

  • Members
  • 7 posts

Posted 12 April 2015 - 11:11 PM

Ok, new design

Spoiler

Error Msg:
bal:11 attempt to index ? (a nil value)

#4 black_hawk143

  • Members
  • 7 posts

Posted 12 April 2015 - 11:40 PM

Ok,

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

Spoiler


#5 flaghacker

  • Members
  • 655 posts

Posted 13 April 2015 - 07: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 by flaghacker, 13 April 2015 - 07:42 AM.


#6 black_hawk143

  • Members
  • 7 posts

Posted 13 April 2015 - 11:40 PM

Quote

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

Edited by black_hawk143, 13 April 2015 - 11:42 PM.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 April 2015 - 11:45 PM

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".

#8 black_hawk143

  • Members
  • 7 posts

Posted 14 April 2015 - 12:57 AM

Good News!
Problem 01 is solved.

This is the first code that I wrote. :D

Working Script:
Spoiler

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")

#9 black_hawk143

  • Members
  • 7 posts

Posted 14 April 2015 - 03: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

Edited by black_hawk143, 14 April 2015 - 03:21 AM.


#10 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 April 2015 - 03: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.

#11 black_hawk143

  • Members
  • 7 posts

Posted 15 April 2015 - 03: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?

[color=#000000][font=arial, helvetica, sans-serif]
Spoiler


#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 April 2015 - 06: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?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users