82 posts
Posted 28 October 2013 - 11:21 AM
I'm working on a "store" program, and I will be trying to pull a player's information out of a database on another presumably hidden computer. The problem is, the database computer doesn't seem to be sending the table back to the right computer, nor does it seem to be receiving the correct message. The database computer prints out "monitor" and the client computer does nothing after broadcasting playername.
(my playername, that it should send, is popdog15)
store-client computer code:
Spoiler
-- setup things
rednet.open("back")
textutils.slowWrite("Rednet opened on back side.", 20)
rednet.broadcast("monitor")
rednet.broadcast("database")
pd = peripheral.wrap("top")
sleep(3)
x = 0
function getDatabaseData(player)
rednet.broadcast(player)
playerTable = {}
print("Broadcasted "..player.." !")
local sender, msg, dist = rednet.receive()
playerTable = textutils.unserialize(msg)
print("Unserialized table-string!")
term.clear()
term.setCursorPos(1,1)
getPlayerTable(msg)
term.write(playerTable[1])
term.setCursorPos(1,2)
term.write(playerTable[2])
end
function getUser()
local event, userData = os.pullEvent()
if event == "player" then
print(userData)
if x == 1 then
getUserWants()
else
getDatabaseData(userData)
end
end
end
function getUserWants(player)
term.clear()
term.setCursorPos(1,1)
print("Welcome,"..player.."!")
print("1) Items for sale")
print("2) Items you can sell")
print("3) Check your credit")
print("4) Check your info")
print("5) Log out")
write("Your choice: ")
choice = read()
if choice == "1" then
print("Showing items for sale.")
checkItems()
elseif choice == "2" then
print("Showing items available for you to sell")
sellableItems()
elseif choice == "3" then
print("Checking credit!")
checkCredit()
elseif choice == "4" then
getUser(player)
x = 1
elseif choice == "5" then
print("Logging out")
os.reboot()
end
end
getUser()
Database computer code:
Spoiler
-- wait for input
local sender, msg, dist = rednet.receive()
getTable = {}
rednet.open("back")
function loadFileFromTable()
local temp
local loadFile = fs.open("database", "r")
while true do
temp = loadFile.readLine()
if temp ~= nil then getTable[temp] = true else break end
end
loadFile.close()
end
function checkForFile()
if fs.exists("database") == true then
loadFileFromTable()
else h = fs.open("database", w)
h.close()
print("File didn't exist, k?")
end
end
print(msg)
checkForFile()
sleep(.1)
tablestring = textutils.serialize(getTable)
rednet.send(sender, tablestring)
33 posts
Location
Area51,Nevada,USA
Posted 28 October 2013 - 11:28 AM
your function loadFileFromTable() is 1 letter to long to label a function
33 posts
Location
Area51,Nevada,USA
Posted 28 October 2013 - 11:32 AM
maybe thats your error
82 posts
Posted 28 October 2013 - 11:45 AM
maybe thats your error
Not the error, I changed it to loadTable()
724 posts
Location
Kinda lost
Posted 28 October 2013 - 11:55 AM
Are you sure there is no other computer in area broadcasting messages? cause from first look at your Database it will answer to first message form any computer and then stop working (no loop)
82 posts
Posted 28 October 2013 - 12:03 PM
Are you sure there is no other computer in area broadcasting messages? cause from first look at your Database it will answer to first message form any computer and then stop working (no loop)
Positive.
48 posts
Location
France
Posted 28 October 2013 - 12:10 PM
I would consider rethinking the flow of this program. The database part looks like it's doing exactly what you're telling it to - listening for one rednet message, sending one out, then terminating. You'll need a "while true do" in there somewhere to listen for the next message(s) from the client.
82 posts
Posted 28 October 2013 - 12:29 PM
I would consider rethinking the flow of this program. The database part looks like it's doing exactly what you're telling it to - listening for one rednet message, sending one out, then terminating. You'll need a "while true do" in there somewhere to listen for the next message(s) from the client.
I know the database is doing everything correctly. I simply don't understand where it's getting "monitor" from, and why the store client isn't printing the table information.
48 posts
Location
France
Posted 28 October 2013 - 12:34 PM
The client is broadcasting it the string "monitor" on Line 4. It's doing "sleep(3)" when the database tries to send it the table 0.1 seconds later. Then the database quits in protest.
82 posts
Posted 28 October 2013 - 12:51 PM
The client is broadcasting it the string "monitor" on Line 4. It's doing "sleep(3)" when the database tries to send it the table 0.1 seconds later. Then the database quits in protest.
I am a dumbass, and I'm embarrassed for making you point that out to me.
48 posts
Location
France
Posted 28 October 2013 - 01:13 PM
No problem, but if you see my silly programs you would not be embarrassed..
93 posts
Location
Somewhere on this earth.
Posted 28 October 2013 - 08:34 PM
Sens your funny! (I like Color [don't forget the Purple in the rainbow!].)