Posted 16 January 2013 - 03:20 PM
Hello, I've been working on an automated atm using computercraft and redpower. And I'm kind of stuck.
Basically what I have it do is accept three types of currency. $1, $5, and $10 tokens. I have a for loop written that will repeat a amount of times based on what the user
inputs when it asks them "how much money do you want to put into the account. I write it as
for i = 1,a do
This way the function can be repeated as many times as the user wants to put in money. Within the function I have an if statement that deals with recognizing the different types of currency. My problem comes when I want the system to store the information in a variable. Say for the account, playerd, I set the variable that stores the balance as playerd. My problem comes when I try and get the system to keep that information. I want the variable to add to itself depending on what currency is inserted. I use
a = io.read()
y = 0
for i = 1,a do
playerd = y + 1
end
print(playerd)
os.sleep(2)
however, this doesn't work because all it does is reset the variable, so the variable playerd always equals 1.
Basically what I have it do is accept three types of currency. $1, $5, and $10 tokens. I have a for loop written that will repeat a amount of times based on what the user
inputs when it asks them "how much money do you want to put into the account. I write it as
for i = 1,a do
This way the function can be repeated as many times as the user wants to put in money. Within the function I have an if statement that deals with recognizing the different types of currency. My problem comes when I want the system to store the information in a variable. Say for the account, playerd, I set the variable that stores the balance as playerd. My problem comes when I try and get the system to keep that information. I want the variable to add to itself depending on what currency is inserted. I use
a = io.read()
y = 0
for i = 1,a do
playerd = y + 1
end
print(playerd)
os.sleep(2)
however, this doesn't work because all it does is reset the variable, so the variable playerd always equals 1.