Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Reading from a txt file? (https://forums.graalonline.com/forums/showthread.php?t=62723)

jake13jake 12-11-2005 06:33 AM

Reading from a txt file?
 
Is there any function that grabs strings from a text file? I've tried looking through the -RC script, but I don't quite grasp what's going on. I just really think that having a message system that can incorporate longer messages than the server vars can handle would be really useful.

ZeLpH_MyStiK 12-11-2005 06:58 AM

There exists no known means of doing this in gs1.

Yen 12-11-2005 08:24 AM

PHP Code:

object.loadvars(path); 

members.loadvars("levels/blah/something.txt");

--CONTENTS OF SOMETHING.TXT--
stuff=3
arf=8
hello="Hi there!"
omg=Yellow,Blue,Red

members.stuff would be 3
members.arf would be 8
members.hellow would be 'Hi there!'
members.omg would be an array containing 'Yellow,' 'Blue,' and 'Red.'

You can get the list of variables it loaded with object.getstringkeys("members");
I don't recall if you need a . after members or not. :/

ApothiX 12-11-2005 08:34 AM

Quote:

Originally Posted by Yen
PHP Code:

object.loadvars(path); 

members.loadvars("levels/blah/something.txt");

--CONTENTS OF SOMETHING.TXT--
stuff=3
arf=8
hello="Hi there!"
omg=Yellow,Blue,Red

members.stuff would be 3
members.arf would be 8
members.hellow would be 'Hi there!'
members.omg would be an array containing 'Yellow,' 'Blue,' and 'Red.'

You can get the list of variables it loaded with object.getstringkeys("members");
I don't recall if you need a . after members or not. :/

There's a way to load textfiles without blah=blah in it too, I just can't remember off the top of my head how to do it :(

This post should have been in the GScript2 sub-forum, though.

jake13jake 12-11-2005 08:41 AM

Quote:

Originally Posted by ApothiX
This post should have been in the GScript2 sub-forum, though.

I would have put it there if I had known that loading from a text file was specifically a gscript2 issue.

ApothiX 12-11-2005 08:45 AM

Quote:

Originally Posted by jake13jake
I would have put it there if I had known that loading from a text file was specifically a gscript2 issue.

It is, indeed.

I was looking through the wiki, and I think what you might be looking for is:

variable.loadlines("filename");

Graal doesn't work on my computer right now, but if memory serves me, it should be something like:
HTML Code:

--levels/test.txt--
Testing 123
Abcdefgh

PHP Code:

this.test.loadlines("levels/test.txt");
echo(
"Line 1: " this.test[0]);
echo(
"Line 2: " this.test[1]); 

Should output:
HTML Code:

Line 1: Testing 123
Line 2: Abcdefgh

(Someone please correct me if I'm wrong)

jake13jake 12-11-2005 09:37 AM

That indeed works. Thanks Apoth.


All times are GMT +2. The time now is 04:42 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.