Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
aslanthekat
Novice


Joined: 17 Sep 2007
Posts: 44
Location: Missouri

PostPosted: Wed Sep 19, 2012 7:27 pm   

variable manipulation
 
Let's say I have the following
Code:
#TR (^(*)$) {#fo @list {#tempvar newline %replace(%line(),%i,"")}}

Is there a way to do this without creating a variable? I want it to manipulate %line() then, when the forall ends, I'll put it in a variable.
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Wed Sep 19, 2012 7:40 pm   
 
Local variables do this,

Code:
#TR (^(*)$) {#fo @list {$tempLine = %replace(%line(),%i,"")};#VAR newline $tempLine}


I'd suggest making your trigger pattern more specific if possible because a script like this checking every line will bog cmud down.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Sep 20, 2012 2:21 pm   
 
It depends on what he intends to do with the final variable. If he needs to do something additional
whether or not the line contains anything from @list, then he may need something like this.
Aslanthekat, can you tell us what this is for?
Reply with quote
aslanthekat
Novice


Joined: 17 Sep 2007
Posts: 44
Location: Missouri

PostPosted: Thu Sep 20, 2012 5:39 pm   
 
When I do a scan I see
Quote:
West (Room is dark):
(Flying) (Demonic) (Sneak) A spectral soldier turns and attacks!
North (Room is dark):
(Flying) (Demonic) (Sneak) A wraith warrior floats here.
South (Room is dark):
(Flying) (Demonic) (Sneak) A wraith warrior floats here.
(Flying) (Demonic) (Sneak) A wraith warrior floats here.
I have all the flags in @list. So the script looks at the line, strips all the flags and then trims any left over spaces leaving me with "A wraith warrior floats here.".
Then I think I'm going to add "A wraith warrior floats here." to a list called WestScan or EastScan or whatever.

This is what I have so far.
Code:
$newline = %1
//Clean up scan lines
#fo @flags {$newline = %remove(%i,$newline)}
$newline = %trim($newline)
//Check if line is a direction
#if (%ismember($newline,%dbkeys(@dirscan))) {
dir = %db(@dirscan, $newline)}
//add newline to proper list
#if (%ismember($newline,@ignorescan)) {} {
#var %concat(@dir,scan) %additem($newline,%concat(@dir,scan))}

This works up until the add newline to list part, but thats a different issue. I can get that.

However, when I set the dir var I tried to use $dir and it didn't work for me. I'm guessing it was a scope issue.

My original question was if I could send %1, or %line() through the forall without assigning any sort of variable. Doing it that way, each time through the loop it it reset itself back to the original %1, so I was ending up with only the last flag in my @flags being removed from the line.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Thu Sep 20, 2012 7:33 pm   
 
No, you can't modify %1 or %line in any way. I don't really see the advantage to doing that versus using a local variable anyway...

EDIT: You could also use a named capture and just reference that local variable instead of %1. You would be able to reassign to that.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net