TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Variable parsing

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Wed Apr 02, 2008 10:20 am    Post subject: Variable parsing Reply with quote

Something simple's confusing me:
Code:
#var {monster} {Oprah}
#high {$monster} {red}
#OK. {$monster} NOW HIGHLIGHTS {red} @ {5}
#act {$monster} {flee}
#OK. {$monster} NOW TRIGGERS {flee} @ {5}.


How do I tweak the commands to get the following result instead:
Code:
#OK. {Oprah} NOW HIGHLIGHTS {red} @ {5}
#OK. {Oprah} NOW TRIGGERS {flee} @ {5}.


(Btw, the period at the end of the "#OK" messages is inconsistent.)
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Wed Apr 02, 2008 10:46 am    Post subject: Reply with quote

Guess I'll fix the period usage. Smile


The action and highlight will work since each time the action or highlight is checked $monster will be translated to whatever value it holds at that moment. That way you don't have to delete and re-create actions or highlights whenever you change $monster.

If you however want to force the substitution of $monster and your session name is quacker you'd use:
Code:

#quaker #high {$monster} {red}
#quaker #act {$monster} {flee}
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Wed Apr 02, 2008 12:33 pm    Post subject: Reply with quote

Scandum wrote:
If you however want to force the substitution of $monster and your session name is quacker you'd use:


Yes, I'm trying to force the substitution (the example I provided is trivial compared to any intended uses). That solution, however leads to some problems.

First of all, if I'm executing the command from a different session, it'll force the variable to be substituted and the syntax would suggest otherwise.

Also, I'd like to force substitutions within aliases and triggers. How would they have access to the session name? Does tintin have a built-in variable that holds the name of each session or would I have to define that explicitly?

In older versions of tintin, "#act {$$monster} {flee}" would do exactly what I'm trying to do.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Wed Apr 02, 2008 1:25 pm    Post subject: Reply with quote

You would have to define a variable to hold the session name:
Code:

#var session quakers
#$session <command>

You don't need to execute it from a different session, so you can use #quakers from within the quakers session.

If you want to avoid variable substitution when communicating between sessions you could use:
Code:

#gts;<command>;#$session


I'm not entirely certain what you're trying to do however, there may be a much easier way to go about it.
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Wed Apr 02, 2008 3:52 pm    Post subject: Reply with quote

Scandum wrote:
I'm not entirely certain what you're trying to do however, there may be a much easier way to go about it.


I'm simply trying to duplicate tintin's old behavior (and wintin.net's current behavior): Have something like
Code:
#var monster Oprah
#act {$$monster} {flee}
#Ok. {Oprah} now triggers {flee} @ {5}


I used to be able to have scripts automatically and dynamically generate multiple actions and substitutions. Using the session commands is much more roundabout than parsing $$variable but they'll work. Confused

Incidentally, why don't sessions have built-in variables? The name of the current session is a no-brainer. Likewise, using #format to access the current screen width and height is indirect compared to having built-in $screenwidth and $screenheight variables.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Wed Apr 02, 2008 4:54 pm    Post subject: Reply with quote

The old behavior for variables was inconsistent if not insane. Pretty much every other script help post on the wintin forum was about the odd way variables worked where someone would either have to use $$ or $$$ to get something simple to work.

I hope you understand I have little desire to go back to that.

You could use something like the following however:

Code:

#var monsters {Oprah Jerry Bubba}

#forall {$monsters}
{
  #high {&0} {red}
  #act  {&0} {flee}
}
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Wed Apr 02, 2008 7:00 pm    Post subject: Reply with quote

Scandum wrote:
The old behavior for variables was inconsistent if not insane. Pretty much every other script help post on the wintin forum was about the odd way variables worked where someone would either have to use $$ or $$$ to get something simple to work.


Yeah, I was glad to get rid of those in my old scripts. This instance, however, isn't as complicated since it involves only two entities- $monster (the variable) and $$monster (the variable's current value). $$$monster wouldn't make sense. Changing the syntax to use a different symbol (eg. &monster) would be cleaner; I just want a direct way to use a variable's current value rather than the variable itself.

Quote:
You could use something like the following however:


Here's a silly but simple example:
Code:
#act {%1 starts following you.} {#var nuisance %1}
#al {harass} {#act {$nuisance has arrived.} {trip $nuisance};#act {$nuisance stands up.} {trip $nuisance}}


As is, the harass alias would create triggers only for the current nuisance. If the script had access to $$nuisance instead, triggers for all previous nuisances would be preserved. I don't want to create triggers for every follower automatically because not all followers would be nuisances.
Back to top
View user's profile Send private message
wanderinweezard



Joined: 12 Mar 2008
Posts: 11

PostPosted: Thu Apr 03, 2008 6:02 am    Post subject: Reply with quote

My apologies to Quackers, I'm not trying to hi-jack the thread. Just a quick question that seems somewhat relevant to the current topic.

is it possible to dynamically retrieve current session name? It relates to my other thread where Scandum showed me how to use #showme to send messages to another session.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Thu Apr 03, 2008 9:22 am    Post subject: Reply with quote

Quackers wrote:

As is, the harass alias would create triggers only for the current nuisance. If the script had access to $$nuisance instead, triggers for all previous nuisances would be preserved. I don't want to create triggers for every follower automatically because not all followers would be nuisances.


Easier said then done given the way tintin works now. I'll try to add a command to deal with this in the near future.

Here is a more universal way to go about it:

Code:

#act {%1 starts following you.} {#var nuisance %1}

#alias {harass}
{
    #forall {$nuisance}
    {
        #act {&0 has arrived.} {trip &0};
        #act {&0 stands up.} {trip &0}
    }
}


#regexp will work in a mutual fashion as well and would allow you to add some additional string checks while at it.
Back to top
View user's profile Send private message Send e-mail
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Thu Apr 03, 2008 9:24 am    Post subject: Reply with quote

wanderinweezard wrote:
is it possible to dynamically retrieve current session name? It relates to my other thread where Scandum showed me how to use #showme to send messages to another session.

The following should work:
Code:

#act {^#SESSION '%0' CONNECTED TO '%1' PORT '%2'} {#var session %0}
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Thu Apr 03, 2008 10:23 am    Post subject: Reply with quote

Scandum wrote:
The following should work:
Code:

#act {^#SESSION '%0' CONNECTED TO '%1' PORT '%2'} {#var session %0}


It'd be nice to have built-in variables for other values like ip address, mud's ip address, mud's hostname, port #, and time connected. Sure, they can be defined explicitly but that's inefficient, especially for novice users.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Thu Apr 03, 2008 11:47 am    Post subject: Reply with quote

I'll probably add support for them one day, I'm not exactly sure about the best way to go about it yet.

Btw, I don't think novice users would have much use for built-in variables. Coffee
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Thu Apr 03, 2008 1:04 pm    Post subject: Reply with quote

Scandum wrote:
Btw, I don't think novice users would have much use for built-in variables. Coffee


Code:
#prompt {<%1 hp> } {[$time] <%1 hp>}

say I better leave. I've been online for $connected minutes.

#al {healme} {cast 'heal' $session}

#if { "$hostname" == "achaea.com"} { something }

#if { "$port" == "4321"} { #read arena_script.txt }

#if { $screenwidth < 80 } { #sub someveryverylongstring shortstring }

#var wordwrap 72


zMUD has several nice built-in variables.

Sad
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Thu Apr 03, 2008 1:43 pm    Post subject: Reply with quote

For the time being you can create your own however.

Code:

#function {time}
{
    #format result %T;
    #format result %t $result
}

#nop To work around the #function bug with prompts:

#act {<%1 hp> }
{
    #showme {[@time{}] <%1 hp>} {1};
    #gagline
}
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group