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

Variables within Substitutes

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



Joined: 08 May 2014
Posts: 3

PostPosted: Wed Jul 23, 2014 11:37 am    Post subject: Variables within Substitutes Reply with quote

I'm trying to make my own price list using substitutes. I have triggers to capture an item's long description and price when I sell something, but it's the final formatting that's getting me.

I use this command:

#action {^The shopkeeper now has %1.} {#if {$pricing == 2} {#var pricing 1;#sub {%1}{%1 <bea>($lastprice)}}}

I get this result:
#SUBSTITUTE {an elven silver breastplate}={an elven silver breastplate <bea>($lastprice)} @ {5}

I want this result:
#SUBSTITUTE {an elven silver breastplate}={an elven silver breastplate <bea>(547)} @ {5}

Is there some special format I use within the trigger to tell it to store the current value of the variable instead of the variable reference? The way it's working now, every item will always show the price of whatever I happened to sell last, instead of its own price.

Thanks,

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


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Thu Jul 24, 2014 7:08 am    Post subject: Reply with quote

You can use #line sub var {<string>} to force the substitution of variables.
Back to top
View user's profile Send private message Send e-mail
galactahack



Joined: 08 May 2014
Posts: 3

PostPosted: Thu Jul 24, 2014 12:05 pm    Post subject: Reply with quote

Thanks, that worked out very well!
Back to top
View user's profile Send private message
bowlshelf



Joined: 31 Jul 2017
Posts: 2

PostPosted: Mon Jul 31, 2017 10:44 am    Post subject: Reply with quote

Update: This ended up helping: http://tintin.sourceforge.net/board/viewtopic.php?t=2442&highlight=force+variable+substitution

Working example:
Code:
#var counter 0; #foreach {{Bob}{Jim}{Tom}} {name} {#line substitute variable #delay 1 {#echo $name}}



galactahack wrote:
Thanks, that worked out very well!


Can you post the example solution? I am having trouble understanding how #line works...

My example problem is that Tom gets displayed all 3 times:

Input
Code:
#var counter 0; #foreach {{Bob}{Jim}{Tom}} {name} {#delay 1 {#echo $name}}


Output:

Quote:
#OK. VARIABLE {counter} HAS BEEN SET TO {0}.
#OK, IN {1} SECONDS {#echo $name} IS EXECUTED.
#OK, IN {1} SECONDS {#echo $name} IS EXECUTED.
#OK, IN {1} SECONDS {#echo $name} IS EXECUTED.
Tom
Tom
Tom
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Mon Jul 31, 2017 12:52 pm    Post subject: Reply with quote

bowlshelf wrote:

Output:

Quote:
#OK. VARIABLE {counter} HAS BEEN SET TO {0}.
#OK, IN {1} SECONDS {#echo $name} IS EXECUTED.
#OK, IN {1} SECONDS {#echo $name} IS EXECUTED.
#OK, IN {1} SECONDS {#echo $name} IS EXECUTED.
Tom
Tom
Tom


As you can see from the messages above, the #delay is using "$name", a variable, so when it is executed it uses the actual content of that variable, and it is "Tom", because the #foreach is already over and "$name" contains the final name.

If instead you resolve the variable part during the declaration of the #delay, it will not be linked to a container, but exactly to the string that formerly was in that variable at the time of the declaration.
This is what "#line sub var" does.

and you will see something like this:
Code:

#var counter 0; #foreach {{Bob}{Jim}{Tom}} {name} {#line substitute variable #delay 1 {#echo $name}}
#OK. VARIABLE {counter} HAS BEEN SET TO {0}.
#OK, IN {1} SECONDS {#echo Bob} IS EXECUTED.
#OK, IN {1} SECONDS {#echo Jim} IS EXECUTED.
#OK, IN {1} SECONDS {#echo Tom} IS EXECUTED.
Bob
Jim
Tom
Back to top
View user's profile Send private message
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