Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Outputting to a text file

Outputting to a text file

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Connla   Eritrea  (4 posts)  Bio
Date Mon 26 Apr 2004 08:26 AM (UTC)
Message
I'm trying to write a file to write mob stats to a text file for inclusion in an excel spreadsheet. I already have all the stats in variables (%mobImmune, %mobResist, etc) and i figured I'd need an alias to write the first keyword i put in(mob name, which doesnt show up) as the first word and the second word(area location which doesnt show up either). This is what I have so far:

Sub WriteToFile(filename, text)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fs.OpenTextFile(filename, 8, True )
file.Write text & vbCrLf
file.Close
world.DeleteVariable "mobsImmune"
world.DeleteVariable "mobsAtt"
world.DeleteVariable "mobsVuln"
End Sub

so that it deletes the variables once it writes them (some mobs dont have all 3 of those pieces of data)

my alias is this:

add * *

WriteToFile ("mobs.txt",%1 & %mobsAtt & %mobsStats & %mobsImm & %mobsRes & %mobsVuln & %2) in command

I get this error message when i try doing /add Barliman Bree, for example:
-2146827263
Execution of line 1 column 11
Expected end of statement
Line in error:
add Barliman Bree
Called by:Immediate execution

Any help would be greatly appreciated.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #1 on Mon 26 Apr 2004 06:48 PM (UTC)
Message
Hmm. There is a fairly good reason for this. Script engines only recognize *their* types of variables. Since Mushclient doesn't use a built in system, but relies on external scripting, VBScript sees % and doesn't have a clue what to do with it. If you where using Java, you would get a completely different error as well, since in Java % would mean divide the previous variable by the next one and return a remainder. To do this correctly you have to first 'retrieve' the values, either directly (by retrieving them in the call to WriteToFile) when needed or by placing them into VBScript variables:

Direct way>

WriteToFile ("mobs.txt", wildcards(1) & getvariable("mobsAtt") & getvariable("mobsStats") & getvariable("mobsImm") & getvariable("mobsRes") & getvariable("mobsVuln") & wildcards(2))

Retrieving them before>

dim mobsAtt, mobsStats, mobsImm, mobsRes, mobsVuln
mobsAtt = getvariable("mobsAtt")
mobsStats = getvariable("mobsStats")
mobsImm = getvariable("mobsImm")
mobsRes = getvariable("mobsRes")
mobsVuln = getvariable("mobsVuln")
WriteToFile ("mobs.txt",wildcards(1) & mobsAtt & mobsStats & mobsImm & mobsRes & mobsVuln & wildcards(2))

Note - wildcards is the 'name' used when defining the last variable in a call to scripting from triggers or aliases, depending on what you called it, you need to use that name, example:

sub Capture_MobInfo (name, out, wilds)

you would use 'wilds' instead of wildcards.

The only time you can use things like %1, or the new %<name> syntax in v3.48, is inside the 'send' field of the trigger or alias. And in that case, if you are using the 'send to script' option, you still need to use "%1" or "%<name>", since mushclient does 'direct substitution'. In other words if you had and alias with 'send to script' like:

<alias
enabled="y"
match="Dostuff * *"
sendto="12">
<send>note %1 & %2</send>
</alias>

If you typed 'Dostuff fred ginger', the script would see this as:

note fred & ginger

This would produce a blank line, since the script thinks fred and ginger all variable names, not data. By changing it to:

<send>note "%1" & "%2"</send>

You would correctly get:

note "fred" & "ginger"

This may seem inconvenient, but it has the interesting side effect of meaning that you can make a wildcard execute a script command:

<alias
enabled="y"
match="Doit *"
sendto="12">
<send>%1</send>
</alias>

'Doit note "Hi there!"' would then execute %1 as a command directly to the scripting system and produce a note in the output window.

If you are not using 'send to script', then you don't need to worry about "", since you are not asking the script engine to handle it.

Hope this all makes sense to you. ;)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 26 Apr 2004 09:37 PM (UTC)
Message
Quote:

WriteToFile ("mobs.txt",%1 & %mobsAtt & %mobsStats & %mobsImm & %mobsRes & %mobsVuln & %2)


An alternative is to fix the two problems here.


  1. The "variable expansion" character is "@" and not "%" (and make sure "expand variables" is checked)
  2. These are strings so you need to quote them


Something more likely to work is:

WriteToFile ("mobs.txt","%1" & "@mobsAtt" & "@mobsStats" & "@mobsImm" & "@mobsRes" & @mobsVuln" & "%2")

Also, if you are doing a spreadsheet I might put in the odd tab character between the fields, otherwise the numbers will be a huge jumble.

You use %1 for wildcards but @mobsAtt for variables.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Connla   Eritrea  (4 posts)  Bio
Date Reply #3 on Mon 26 Apr 2004 10:30 PM (UTC)
Message
I'm not sure if I've done this right, but I changed my script to:

Sub WriteMobInfo
dim mobsAtt, mobsStats, mobsImm, mobsRes, mobsVuln,fs,file
mobsAtt = getvariable("mobsAtt")
mobsStats = getvariable("mobsStats")
mobsImm = getvariable("mobsImm")
mobsRes = getvariable("mobsRes")
mobsVuln = getvariable("mobsVuln")
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("c:\mobs.txt", 8, True )
file.Write mobsAtt & mobsStats & mobsImm & mobsRes & mobsVuln & vbCrLf
file.Close
world.DeleteVariable "mobsImm"
world.DeleteVariable "mobsRes"
world.DeleteVariable "mobsVuln"
End Sub


just so i could test it. I tried it both with and without the file there, and either way nothing happened. I changed my add alias to just output "WriteMobInfo"(minus quotes) to Script, because I kept getting errors about using parentheses when I had it as "WriteMobInfo (name,area)". All in all I'd say I'm very confused.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 26 Apr 2004 10:56 PM (UTC)
Message
If you are calling this from an alias I would have the first line as:

Sub WriteMobInfo (name, line, wildcards)


Then, rather than sending WriteMobInfo "to script", put WriteMobInfo into the "script" box (ie. the name of the script to call).

Make sure scripting is enabled and your script file is listed as the script file to process.

Put in a note to make sure the script is actually being called, eg.

Sub WriteMobInfo (name, line, wildcards)
world.Note "WriteMobInfo called"

...
end sub



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Connla   Eritrea  (4 posts)  Bio
Date Reply #5 on Mon 26 Apr 2004 11:22 PM (UTC)
Message
Ive gotten it to call the subroutine and write the file when just executing "add" and having "WriteMobInfo" in the script textbox, but how do I expand that to allow me to do something like "add Sauron Mordor" and have that be sent to the sub, or do I have to set those as variables and then get it from the sub(and if so, how do i set more than one world variable)?

Thanks for all your help
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Mon 26 Apr 2004 11:35 PM (UTC)
Message
OK, now we have it as a script file sub, your wildcards are in the wildcards argument.

eg. if the alias is: add * *

and you type: add Sauron Mordor

Then:

wildcards (1) is Sauron

and

wildcards (2) is Mordor

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Connla   Eritrea  (4 posts)  Bio
Date Reply #7 on Mon 26 Apr 2004 11:53 PM (UTC)
Message
Thanks for everybody's help, I finally got it to work. Since I can't get the name from its stats, I modified it so I set the area with an alias when I enter a new area and when I look at the mob it gets its name. Thanks again :)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


22,785 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.