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

[Begginer] Make a slot machine ?

Started by ZoumeyZ, 17 March 2012 - 05:22 PM
ZoumeyZ #1
Posted 17 March 2012 - 06:22 PM
Hello everyone ! this is my first post :D/>/>


So , yeah , i had in mind to make a casino or something like that with tekkit. actually , i've coded a lot with gmod's E2 ( a simplified lua code) but I still don't understand everything.


so , i wanna make a slot machine , i know how it should work.

The Slot Machine


note that the tekkit version is not updated , if it was, i'll use screen and a lever.

so basically , the computer have a startup programs and for it to work you'll have to put an item in a chest , and a redpower block will suck it out. it will with another redpower block send a redstone signal to the computer , who'll start doing the slot machine's job. if it happen that the user win , it will send some signal behind it to make some music and some signal down to launch the price out of the dispenser.

that's the basic idea , but i have a lot of problems with code.

so first : how do i make the letters and number "roll" like an actual slot machine ? i had the idea to give each of them a number

(for instance , O = 1 ; X = 10 ; V = 50)

so if the total result is 3 , or 30 , or 150 , you'll win. but , then again , i don't know how to value … a value.

thank's for reading and/or helping me.

ZoumeyZ
Advert #2
Posted 17 March 2012 - 11:50 PM
You can make the numbers/letters roll with something like this:


local s = "ABO17ABOO" -- etc, whatever you want here.
local pos = 1 -- the position we're at


local function genRoll(s, n)
 local len = #s
 local s = s .. s
 local n = n + len
 return string.sub(s, n-1, n-1), string.sub(s, n, n), string.sub(s, n+1, n+1) 
end

print(genRoll(s, pos))
pos = pos+1
print(genRoll(s, pos))
pos = pos+1
print(genRoll(s, pos))


Of course, this is not optimized, and you only get one roll, but you can make it OOP/use tables to store possiblities quite easily and have multiple of them.

Result of above: http://ideone.com/pufjc
ZoumeyZ #3
Posted 18 March 2012 - 02:20 AM
Well , thank you ! that definitely not that sort of code I expected to have. but , thank you a lot ! i could never done it without your help !

now , another problem : you put all the rolling text in one string (ABO17ABOO) so i don't know how to get something when we've got a line out of one letter/number. i think the only way to make it work is to check if it's possible to have a 3 in a row and code the position for each situation you can win. but , it won't be optimized at all..?
Advert #4
Posted 18 March 2012 - 02:47 AM
Well , thank you ! that definitely not that sort of code I expected to have. but , thank you a lot ! i could never done it without your help !

now , another problem : you put all the rolling text in one string (ABO17ABOO) so i don't know how to get something when we've got a line out of one letter/number. i think the only way to make it work is to check if it's possible to have a 3 in a row and code the position for each situation you can win. but , it won't be optimized at all..?

In the above example, you'd call genRoll 3 times (for a 3 line machine):

http://ideone.com/ZYnuT

The pos variable was just to demonstrate how you might use it to show a rolling animation; i've skipped it for this example, though.
ZoumeyZ #5
Posted 18 March 2012 - 12:20 PM
Thank you a lot ! now i just need to print them in the middle of the screen , and add the effect if we win. hope i won't have lot of problems ! :D/>/>