ID:898484
 
(See the best response by DarkCampainger.)
Is there a proc that can be used to return a text, started from arg1 and ended on arg2 ?
Best response
Your description is rather vague, but I think you want copytext().
Actually, it was. I was looking it up before, but i think i missunderstood its purpose.
Seems to be what im looking for after all. :)
I have done this in a few ways now, but it won't return anything. Have any idea what it might be? :o

proc
read_file( file, index ) // Return: Value of "index"
var/value
value = copytext(file2text(file), index + "=", ";")

return value

mob/Login()
var/reader = read_file("text.txt", "inc")
world << reader

/* text.txt:
inc=15257;
*/
You have to use findtext(text, find) to do that. It won't automatically find those characters.
I don't think you understand. How can findtext help me when there is nothing to find?

I want to return what is between index = and ;
which in this case would be 15257.

[EDIT]
May this work?
findtext(file2text(file),, index + "=", ";")
var/text = "=15257;"
var/i = findtext(text, "=")+1 // start AFTER the =
var/end = findtext(text, ";")
var/what_you_need = copytext(text, i, end)
you miss my point :/
I need to find something that isn't constant.
i want to refer data to a file in short sentences, which i can change.

This solution wont work :/

for example
mob/var/strenght = read_file("mob_var.txt","strengt")
I don't see how my suggestion was not helpful. You just need to store the file's text in a variable, then search for what you want. In your example, if you do findtext(string, "strengt"), it will return where that bit of text starts in the string.
Im sorry. It gave me a few ideas, but none of them worked.
But thanks however
proc
read_value( file, index ) // Return: Value of "index"
var/value

var/text = findtext(file,index)
var/i = findtext(text, "=") +1
var/end = findtext(text, ";")

value = copytext(text, i, end)

return value

mob
Login()
world << read_value("1.txt", "loginData")
In response to Tafe
You still need to use file2text, as so:
 proc
read_value( file, index ) // Return: Value of "index"
var/value

var/text = findtext(file2text(file),index)
var/i = findtext(text, "=") +1
var/end = findtext(text, ";")

value = copytext(text, i, end)

return value

mob
Login()
world << read_value("1.txt", "loginData")


In response to Tafe
Also, may I ask how your text file is organized? There may be a simpler way to do this.
iv tryed it. it doesn't work.
Simply sais: loginData=15256;

just a random number to output. thats all
Note that if this is set up like you said it was before, text and i are going to be the same thing in SSX's example. You will be using findtext() on a number. Use his example, except only keep the file2text() on that line; remove findtext() from around it. You need to file2text() it and then search for what you need.
In response to Albro1
Albro1 wrote:
Note that if this is set up like you said it was before, text and i are going to be the same thing in SSX's example. You will be using findtext() on a number. Use his example, except only keep the file2text() on that line; remove findtext() from around it. You need to file2text() it and then search for what you need.

Err. Yeah, I have no clue why I left findtext() around it.
It was meant to be a copytext, or something. I was thinking ahead of what was actually done.

He'd actually have to do something like:
proc
read_value( file, index ) // Return: Value of "index"
var
text = file2text(file(file))

findex = findtext(text,index)

end = findtext(text, ";")

i = findtext(text, "=", findex, end) +1

value = copytext(text, i, end)

return value

mob
Login()
world << read_value("1.txt", "loginData")
..()


I avoided using copytext here, because copytext is one of the most CPU intensive text procs, apparently.
His main problem was: he forgot to use file().
Otherwise, DM wouldn't know it's an actual file. filet2text() needs an actual file, not the name of the file as a text reference.
Huh. Hasn't shown any problems for me, and I made a script reader that lets you type out cutscenes in .txt files. Needless to say, copytext() is used quite a bit. It is a single-player game, though. Well, you learn something everyday, hm?
In response to Albro1
Albro1 wrote:
Huh. Hasn't shown any problems for me, and I made a script reader that lets you type out cutscenes in .txt files. Needless to say, copytext() is used quite a bit. It is a single-player game, though. Well, you learn something everyday, hm?

Well, I dunno. Someone told me that, some time ago. So instead, eh, I've just been findtext(), and then copytexting only when I need to, instead of constantly making a shorter string. Anyways, his main problem was that he was never using file() on his text reference.
fell asleep last night, so didn't see the replies. thanks for your help ss
found an error...
end     =   findtext(text, ";")
end = findtext(text, ";", findex)

Didn't read from findex, so it would choose the first ; it found, and change value to everything before it.