#1
Posted 11 June 2013 - 05:53 PM
I am making a banking program that uses a table to store the values. I would like for it to use their playernames as the index of the table but it won't let me do a string longer than 1 character. So I am looking for a way to convert a string into a number that can be decoded back into a string. Also I forgot to mention it uses openccsensors to get the playername securely. It has a server at the top of the building that stores the table into a file with textutils.serialize() but I can't get the table to work because it won't let me use strings. thank you for any help.
#2
Posted 11 June 2013 - 05:55 PM
#3
Posted 11 June 2013 - 06:08 PM
As for your question: How long are the strings you're trying to convert to numbers? I have a method you could use in mind, but it can only hold a limited number of characters.
#4
Posted 11 June 2013 - 06:28 PM
you can index a string (i know, its weird but true)
for example:
for char in str:gmatch(".") do
works fineas to the OP, you cannot put more than 3 or 4 characters into a single number
but you can use string.byte, why would you need to anyway?
the last time i recall needing it was to make an extremely inneficient encryption algorithm (i didnt know what i was doing)
if you want to make the string human unreadable, go look for a base64 implementation, i know StrUtils has one
#5
Posted 11 June 2013 - 06:46 PM
#6
Posted 11 June 2013 - 09:19 PM
test["testing"]=0 ERROR: line 1: attempt to index global 'test' (a nil value) stack traceback: t.lua:1: in main chunk [C]: ?
Also PixelToast Your code seems like it might work but I have no clue how to use it lol. Also the strings would vary in length as I specified they are playernames.
Edited by superanonymous, 11 June 2013 - 09:22 PM.
#7
Posted 11 June 2013 - 09:28 PM
#8
Posted 11 June 2013 - 09:32 PM
local test = {}
-- Your Code:
test["testing"] = 0
But I don't know how you got that error. I got:
test:2: index expected, got nil
#9
Posted 11 June 2013 - 09:59 PM
#10
Posted 11 June 2013 - 10:20 PM
D:\Program Files (x86)\Lua\5.1>lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> myTab = {}
> myTab.testing = 0
> myTab["testingtwo"] = 3
> print(myTab.testingtwo)
3
> print(myTab["testing"])
0
>
#11
Posted 12 June 2013 - 07:46 AM
#12
Posted 12 June 2013 - 07:51 AM
#13
Posted 12 June 2013 - 07:54 AM
superanonymous, on 12 June 2013 - 07:46 AM, said:
#14
Posted 12 June 2013 - 07:59 AM
http://pastebin.com/L1HJAxxN
#16
Posted 12 June 2013 - 08:05 AM
theoriginalbit, on 12 June 2013 - 08:00 AM, said:
Orwell, on 12 June 2013 - 07:54 AM, said:
#17
Posted 12 June 2013 - 08:09 AM
Orwell, on 12 June 2013 - 08:05 AM, said:
theoriginalbit, on 12 June 2013 - 08:00 AM, said:
Orwell, on 12 June 2013 - 07:54 AM, said:
#18
Posted 12 June 2013 - 08:55 AM
And the closest player thing won't work because the proximity detector can detect all mobs and I don't think they're returned in order of distance.
Also you don't need to do that whole thing with serializing k then stripping quotes, you can just return k.
Slightly fixed code:
Fixes:
- getclosestplayer only returns players not all mobs
- The value is properly initialized
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











