 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 1:16 pm
trying to read a file issue |
I really wanna get cmud to work! So far, I like the ideas... Having said that... I'm having an issue with reading a file. The text file is named NOD_filename.txt and I have an alias that reads the file, and loads the information in there (not important to this thread, so I'll just leave it at that...) The problem is that it says "Opened NOD_ as file 1" then, when the alias checks the format of the opened file, it obviously is wrong so it says "Invalid script file." because the file that it opened was not the correct one. With zmud, it worked fine. I'm pretty sure its the change of %1 to $name, but I can't seem to figure it out.... Here's the alias.... As it stands, straight from my old zmud file. Thanks again! (Also, on a side note... How come cmud doesn't auto format the code? IE it has coloring, but it doesn't delete the ;'s and move them to the next line, and indent as needed? I really liked that, as some things can get VERY long, and it made it alot easier to read... IMHO... Anywho... Here's the alias!)
#ALIAS load {#if (@bsync) {#variable scriptstate %1;#variable bkill 1;#variable key_list {};#variable sob_list {};#variable gob_list {};#variable mob_list %array( 0);#variable line 2;#file 1 NOD_%1.txt;#variable line_max %filesize( 1);#if (%word( %read( 1, 1), 1) = "MOBDEF") {#loop 0,%eval( %word( %read( 1, 1), 2) - 1) {#noop %arrset( mob_list, %i, 0);#variable key_list %additem( %word( %read( 1, @line), 2), @key_list);#add line 1;#variable sob_list %additem( %read( 1, @line), @sob_list);#add line 1;#variable gob_list %additem( %read( 1, @line), @gob_list);#add line 1};#if (%read( 1, @line) = "PATH") {#status {Go to starting room and use 'begin' to start.}}} {#echo Invalid script file.}} {#echo Tick not synched! Synch time first...}} |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed May 07, 2008 2:06 pm |
Couple of things: Arrays are only really meant for passing to COM objects. You'll probably find a stringlist more useful.
There's no $name mentioned here, so obviously you've changed something for the CMUD version (which isn't working) that you haven't mentioned here. What changes have you made?
The pretty printer (because that's what it was called) was removed because it was buggy as hell. It'd move your cursor round all over the place so you ended up typing in the middle of something a lot of the time. In CMUD, you can just put in a line break yourself where normally you'd put in a semicolon:
| Code: |
#say something
#say something else |
will work, for example. If a line is indented compared to the one before it, they're treated as if they're a single line:
which lets you make constructs like the old
| Code: |
#if (@something="something") {
#say omg
#var something "Diiiiiive!"
} |
without it thinking the newline after the { is showing a new command. It gives you much more flexibility in laying out you code, so overall, I prefer it this way. |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 2:42 pm |
DOH! The $name, right. I had gone back and forth between my browser and cmud trying to get it be how it was, and I missed that, LoL! Also... for the buggy 'pretty printer'... I liked that... *tear* Ah well, I've got a big learn curve with cmud, cuz I don't think that I was using it to its fullest potential anyways. But I've upgraded to Vista, and want to redo everything, so I can be that much more efficient. =D Thanks for your help by the way. 'Preicate it!!
The upper post is how it was in zmud, and here is what I changed it to in cmud. But... It still didn't work.... This is what I get with the $name change, and I type in load telgoran
#if (@bsync) {#variable scriptstate %1;#variable bkill 1;#variable key_list {};#variable sob_list {};#variable gob_list {};#variable mob_list %array( 0);#variable line 2;#file 1 NOD_$name.txt;#variable line_max %filesize( 1);#if (%word( %read( 1, 1), 1) = "MOBDEF") {#loop 0,%eval( %word( %read( 1, 1), 2) - 1) {#noop %arrset( mob_list, %i, 0);#variable key_list %additem( %word( %read( 1, @line), 2), @key_list);#add line 1;#variable sob_list %additem( %read( 1, @line), @sob_list);#add line 1;#variable gob_list %additem( %read( 1, @line), @gob_list);#add line 1};#if (%read( 1, @line) = "PATH") {#status {Go to starting room and use 'begin' to start.}}} {#echo Invalid script file.}} {#echo Tick not synched! Synch time first...}
[ Line too long : truncating ]
Unknown command: please try again or type 'help' for help.
(Sorry for the yellow, try'n to keep it as similar to what I see from cmud as possible)
#ALIAS load {#if (@bsync) {#variable scriptstate %1;#variable bkill 1;#variable key_list {};#variable sob_list {};#variable gob_list {};#variable mob_list %array( 0);#variable line 2;#file 1 NOD_$name.txt;#variable line_max %filesize( 1);#if (%word( %read( 1, 1), 1) = "MOBDEF") {#loop 0,%eval( %word( %read( 1, 1), 2) - 1) {#noop %arrset( mob_list, %i, 0);#variable key_list %additem( %word( %read( 1, @line), 2), @key_list);#add line 1;#variable sob_list %additem( %read( 1, @line), @sob_list);#add line 1;#variable gob_list %additem( %read( 1, @line), @gob_list);#add line 1};#if (%read( 1, @line) = "PATH") {#status {Go to starting room and use 'begin' to start.}}} {#echo Invalid script file.}} {#echo Tick not synched! Synch time first...}} |
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed May 07, 2008 3:03 pm |
One problem is that you aren't defining $name anywhere. You are trying to use it before it has any value. You can still use %1 in cmud. If you want to use a local variable there, simply add this to the beginning of the script:
$name = %1 |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 3:12 pm |
Well... Initially I had #file 1 NOD_%1.txt then changed it to #file 1 NOD_$name.txt thinking that I was using %1 wrong... Hmmmm... Well, for fault isolation, I think I'm going to remove everything except for the part thats giving me issues. Think that might help... Too much 'filler' in that alias to try and troubleshoot. Hehe....
|
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 3:19 pm |
Yup.... Even this alias isn't working....
#alias {zload} {#file 1 NOD_%1.txt}
Still gives me an "Opening NOD_.txt" So I'm doing something wrong with the alias. Cuz the #filename is pretty straightforward... Heh |
|
Last edited by shaun.murray on Wed May 07, 2008 3:30 pm; edited 1 time in total |
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 3:30 pm |
So then... why doesn't this work?
#alias {load($script)} {#file 1 NOD_$script.txt} Looks right to me... =[ |
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed May 07, 2008 3:39 pm |
When you use the alias, are you actually specifying the script name? That is, are you typing:
load
or are you typing something like:
load myfile
for a script named NOD_myfile.txt? I assume you wouldn't make a mistake like this, but I have to ask since that's the most obvious possible error. |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 3:43 pm |
hahahahaha, ok... that a mistake?
but yea, i am typing load telgoran and the alias automatically puts NOD_ in. and the filename is NOD_telgoran.txt
hence the #file 1 NOD_$script.txt |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed May 07, 2008 3:56 pm |
I'll have a look at this properly when I get home, but my suspicion is that CMUD doesn't like the implicit concatenation. Try changing it to #file 1 ("NOD_" + $name + ".txt") or #file 1 %concat("NOD_",$name,".txt")
where $name is %1 or $script or whatever you decided to use in the end.
However, you wrote above [ Line too long: truncating ] - where are you seeing that? If CMUD's giving you that as an error somewhere, it's possible that that's the problem. There are no linebreaks in your script and it's quite long, so perhaps it's hitting some limit? There probably shouldn't be such a limit, but it's possible that it was overlooked "because nobody would ever type anything that long!"
Oh, and I'm going to change the yellow in that post above. It's practically unreadable. |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 4:25 pm |
Hmmmm.... I get this as an output....
#file 1 ("NOD_" + $script + ".txt")
Unknown command: please try again or type 'help' for help.
Very weird. Ok, I think I'm making this too difficult, I'm going to just rename all the files, and take out the NOD_ and remove that check. To be honest, I think that was used originally to easily see what was a script, and what wasn't.... |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 4:40 pm |
GAR... I removed the NOD_ check. But for some reason now, its telling me that its an invalid script, per the alias.... "Invalid script file." is what I get when I type load telgoran and the file IS named telgoran.txt
| Code: |
| #if (@bsync) {#variable scriptstate %1;#variable bkill 1;#variable key_list {};#variable sob_list {};#variable gob_list {};#variable mob_list %array( 0);#variable line 2;#file 1 %1.txt;#variable line_max %filesize( 1);#if (%word( %read( 1, 1), 1) = "MOBDEF") {#loop 0,%eval( %word( %read( 1, 1), 2) - 1) {#noop %arrset( mob_list, %i, 0);#variable key_list %additem( %word( %read( 1, @line), 2), @key_list);#add line 1;#variable sob_list %additem( %read( 1, @line), @sob_list);#add line 1;#variable gob_list %additem( %read( 1, @line), @gob_list);#add line 1};#if (%read( 1, @line) = "PATH") {#status {Go to starting room and use 'begin' to start.}}} {#echo Invalid script file.}} {#echo Tick not synched! Synch time first...} |
|
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 5:26 pm |
Ok... This is what I have....
| Code: |
| #alias {load} {#file 1 %1.txt;#if (%word( %read( 1, 1), 1) = "MOBDEF") {#say got MOBDEF} {#say didn't load right!}} |
When I type in load telgoran I get this as output didn't load right!. So... I'm thinking that it isn't opening the file right, the first word on the first line of that file IS MOBDEF.... So that #if statement should work for me...
huh.....
Ok this is what I have now...
| Code: |
| #alias {load} {#file 1 nodeka.txt;#if (%word( %read( 1, 1), 1) = "MOBDEF") {#say got MOBDEF} {#say didn't load right!}} |
And when I type load I'm getting the same output. Maybe I have the nodeka.txt file in the wrong place?? |
|
|
|
 |
Larkin Wizard

Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Wed May 07, 2008 5:59 pm |
Just a thought, but maybe it's because the extension isn't in quotes and so it's being treated as a key index into a data record variable rather than a string? Instead of #FILE 1 %1.txt, try either #FILE 1 %1".txt" or #FILE 1 %concat(%1, ".txt")...
Actually, maybe it is just that your files aren't in the right place. By default, CMUD should be loading the file from the same directory as your main package file, I think. You can specify the full (absolute) path, if that'll help you narrow it down. |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 6:10 pm |
Ok... I got the problem. Its the inputting of the filename via an alias. For example:
WORKS
| Code: |
| #alias {load} {#variable key_list {};#variable sob_list {};#variable gob_list {};#variable mob_list %array( 0);#variable line 2;#file 1 telgoran.txt;#variable line_max %filesize( 1);#if (%word( %read( 1, 1), 1) = "MOBDEF") {#loop 0,%eval( %word( %read( 1, 1), 2) - 1) {#noop %arrset( mob_list, %i, 0);#variable key_list %additem( %word( %read( 1, @line), 2), @key_list);#add line 1;#variable sob_list %additem( %read( 1, @line), @sob_list);#add line 1;#variable gob_list %additem( %read( 1, @line), @gob_list);#add line 1};#if (%read( 1, @line) = "PATH") {#say done!!!}} {#say Invalid script file.};#close 1} |
load
DOES NOT WORK
| Code: |
| #alias {load} {#variable key_list {};#variable sob_list {};#variable gob_list {};#variable mob_list %array( 0);#variable line 2;#file 1 %1.txt;#variable line_max %filesize( 1);#if (%word( %read( 1, 1), 1) = "MOBDEF") {#loop 0,%eval( %word( %read( 1, 1), 2) - 1) {#noop %arrset( mob_list, %i, 0);#variable key_list %additem( %word( %read( 1, @line), 2), @key_list);#add line 1;#variable sob_list %additem( %read( 1, @line), @sob_list);#add line 1;#variable gob_list %additem( %read( 1, @line), @gob_list);#add line 1};#if (%read( 1, @line) = "PATH") {#say done!!!}} {#say Invalid script file.};#close 1} |
load telgoran
It does everything in the alias when I specify the file to use within the alias. However.... When I have %1.txt within the alias, and try to load the file using the alias.... That make sense now? I've got it almost... I just need to take %1 from the load command, and insert it into #file 1 %1.txt.....
Thanks everyone for reading my ramblings on this.... Hahahahaha! |
|
|
|
 |
shaun.murray Magician

Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Wed May 07, 2008 6:25 pm |
Larkin! That works! WHOOOHOOOOO!!!!
|
|
|
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|