ID:272810
 
I wanna be able to add "list entries" to a .txt file, and then load those entries into a list var in DM. I have no idea how to go about this :\
You best show us the format you want for the text file.
In response to Stephen001
Uhh >.< Line breaks?

//example info in the .txt file

Entry1
Entry2
Entry3


//when loaded into the list var...
list(Entry1,Entry2,Entry3)
In response to Spunky_Girl
By using file2text(), copytext(), and findtext() or text2ascii().
In response to Popisfizzy
I tried the below code, with the even further below lines in the .txt file, yet it still booted me when I hosted in DD and joined :(

client/New()
if(!findtext(file2text("Savefiles/keys.txt"),src.key))
src<<"Sorry, you're not allowed to connect to this chat room."
del src
..()

Spunky_Girl
Key2
In response to Spunky_Girl
client/New() works only so far but when you have a code specified to do something (boot someone off) it will do it if returned true or false depending on what you want.
In response to Robotyoshi
Sorry but you're absolutely no help. I have it checking to see if it can't find src's key in the .txt file. findtext() returns a text string or null. Since it's booting me, it's returning null (false). I want to know why, and then how to fix that.
In response to Spunky_Girl
/*
This would be a list of ckeys, seperated by linebreaks. For
example, this is an example of how the file could look:
spunkygirl
jtgibson
thefizzmeister
lummoxjr
jp
mobiusevalon
*/

var/reference_file = "Savefiles/keys.txt"

client
New()
if(!IsAllowed())
src << "Sorry, you're not allowed to connect to this chatroom."
sleep(50) //Wait five seconds.
del src //Delete them.

return ..()

proc/IsAllowed()
if(!fexists(reference_file))
//If the file isn't found, output data to the
//world's log and assume that everyone's allowed
//in.
world.log << "Error: No '[reference_file]' found."
return 1

var/file_data = file2text(reference_file)
if(!findtext(file_data, ckey))
//If the ckey isn't found, return 0.
return 0

return 1
In response to Spunky_Girl
You should have noticed that you don't get the output message, however. That "boot" would remain even if you entirely removed the del call - it stems from incorrect usage of client/New(). This proc's return value is checked and is meaningful - it is the mob to connect the player to, or any other value to not connect him to any and disallow the connection. In your override, albeit you're calling the default action, you're discarding its return value, and ultimately returning null (the default value of the . var). You can 'forward' the parent proc's return value and return it in an override by simply using return ..() or a similar statement.
Alternatively, you could use world/IsBanned() to do this checking and block connections through there before a client is created, since you only need the key. Note this does not however work on the host.
Also note checking for a word or entry in a bunch of text directly is not completely reliable - since it simply checks if the text you're looking for is there, it will still find it even if it's a part of another word or entry. For example, a person with the key Dude would be allowed in if the key CoolDude is allowed, because his key can be found amidst the text, even though it's actually in a separate key.
In response to Kaioken
Kaioken wrote:
Also note checking for a word or entry in a bunch of text directly is not completely reliable - since it simply checks if the text you're looking for is there, it will still find it even if it's a part of another word or entry. For example, a person with the key Dude would be allowed in if the key CoolDude is allowed, because his key can be found amidst the text, even though it's actually in a separate key.

Using Pop's method, if I did my own sort of "hashing" method, would it work to prevent the "Dude-CoolDude" mix-up?
//entry in .txt file
!@#$_Dude_$#@! var/file_key = "!@#$_[src.key]_$#@!"
if(findText(file_data,file_key)) //and then use findText(), not findtext()
In response to Spunky_Girl
Or, more easily, make sure that every one has a linebreak at the end (meaning the end of the TXT would need an extra line), and just search ckey + "\n".

Also, that's about as much hashing as it is cryptography.
In response to Popisfizzy
So the list of ckeys would look like...?
spunkygirl

popisfizzy

lummoxjr

kaioken

etc
In response to Spunky_Girl
No, it would look like this:
popisfizzy
jp
lummoxjr
jtgibson
keeth
aza
stephen001
spunkygirl

Note the extra linebreak on the last line.
In response to Popisfizzy
Oh, of course xD

I'm still connecting! Even when I log on with a totally different key. I hosted it on my shell server and not DD this time. Am I doing something wrong? No messages are appearing, so the .txt file is being found...
var/reference_file = "Savefile/keys.txt"
client/New()
if(!Find_Key())
src<<"Sorry, you're not allowed to connect to this chat room."
del src
return ..()

client/proc/Find_Key()
if(!fexists(reference_file))
src<<"Error: no '[reference_file]' found."
return 1
var/file_data = file2text(reference_file)
if(!findText(file_data,ckey+"\n"))
return 0
return 1
In response to Spunky_Girl
You're using the ckey in the file, right? Also, output the value of file_data and see what it shows.
In response to Popisfizzy
Oh my... I'm either totally stupid, or I just had a blond moment >_>

I forgot to "include" the file the snippets are in ;p

Thanks Pop! xD
I'm astonished that not a single person mentioned params2list and list2params.
In response to Schnitzelnagler
Perhaps because it is much less pretty than using other methods of separation such as linebreaks? :P More suitable for other mediums than text files, I think, but of course whatever floats your boat. Also, learning in a non-built-in-proc kind of way is still more beneficial since one learns how to accomplish the matter more generally, and so is not limited to params format or anything. >.>
In response to Kaioken
Would it be beneficial to know how to use parameters in this case for other game programming languages? (such as C++)
In response to Spunky_Girl
yes parameters are very important in other game programming especially with outside files it is very much needed when calling .dll files or the like and parameters or "arguments" are one of the basic needs for function to function communication in C++
Page: 1 2