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 setting in script echoes to screen. How to stop?

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



Joined: 01 May 2017
Posts: 10

PostPosted: Mon May 01, 2017 1:04 pm    Post subject: Variable setting in script echoes to screen. How to stop? Reply with quote

Hello,

I am new to TinTin. I created an action with a raw regular expression and so far it appears to be working. However, within the action script, I reset a variable to a specific value based on a condition. But when I do this, it echoes the variable setting to the screen of gameplay. Why does it do this and how do I stop it from doing that?

When this triggers in game, it prints:

#VARIABLE {hpHealth}={NA}

It doesn't what I set that variable to in code. It could be an empty string {} or something else. It always prints it to the screen.

All of my actions that set a variable with a value echo out to the main screen Sad

Thanks in advance for your help.


Code:

#ACTION {{HP\[(\d+)(?:\((\d+)\)|)\/(\d+)\] SP\[(\d+)(?:\((\d+)\)|)\/(\d+)\] NP\[(\d+)\/(\d+)\|(\d+)c\] E\[(.*?)(?::(.*))?\]}} {
        #VAR hpCurrHP   %2;
        #VAR hpInfHP    %3;
        #VAR hpMaxHP    %4;
        #VAR hpCurrSP   %5;
        #VAR hpInfSP    %6;
        #VAR hpMaxSP    %7;
        #VAR hpCurrNP   %8;
        #VAR hpMaxNP    %9;
        #VAR hpCorInv   %10;
        #VAR hpName     %11;
        #VAR hpHealth   %12;
        #IF {"$hpName" == "none"}{#var hpHealth NA;};
        #SHOWME {HEALTH:  HP: $hpCurrHP/$hpMaxHP  SP: $hpCurrSP($hpInfSP)/$hpMaxSP  NP: $hpCurrNP/$hpMaxNP}{2};
}{1}
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Mon May 01, 2017 8:39 pm    Post subject: Reply with quote

Maybe try using: #debug action on

This might give you an indication as to where things go wrong.

It looks like your script is executing "#var hpHealth" without an argument.
Back to top
View user's profile Send private message Send e-mail
oneor11



Joined: 01 May 2017
Posts: 10

PostPosted: Tue May 02, 2017 6:27 am    Post subject: Reply with quote

Scandum wrote:
Maybe try using: #debug action on

This might give you an indication as to where things go wrong.

It looks like your script is executing "#var hpHealth" without an argument.


Thanks for the reply. Can you elaborate on how I am executing #var hpHealth without an argument? Does #var hpHealth NA set the value to "NA"? Also I turned on debug and suspect that it may have something to do with the variable not getting initially populated because that regex portion was optional and the match didn't exist. Note the capture below. The three variables that report out to the gameplay screen all had their % variables not set. Any ideas? I've highlighted the rows with "<====" in the capture below.

Code:

#DEBUG ACTION {{HP\[(\d+)(?:\((\d+)\)|)\/(\d+)\] SP\[(\d+)(?:\((\d+)\)|)\/(\d+)\] NP\[(\d+)\/(\d+)\|(\d+)c\] E\[(.*?)(?::(.*))?\]}}
[02] variable hpCurrHP  2847
[02] variable hpInfHP
[02] variable hpMaxHP   1619
[02] variable hpCurrSP  1365
[02] variable hpInfSP   177
[02] variable hpMaxSP   1365
[02] variable hpCurrNP  1355
[02] variable hpMaxNP   1355
[02] variable hpCorInv  64
[02] variable hpName    none
[02] variable hpHealth                 <===========
#VARIABLE {hpHealth}={NA}     <===========
[02] variable dummy     NA
[10] if {"none" == "none"}
[02]     unvariable hpHealth
[02]     variable hpHealth NA
[05] endif
[02] showme {HEALTH:  HP: $hpCurrHP/$hpMaxHP  SP: $hpCurrSP($hpInfSP)/$hpMaxSP  NP: $hpCurrNP/$hpMaxNP}{2}
HP[2847/1619] SP[1365(177)/1365] NP[1355/1355|64c] E[none]
#DEBUG ACTION {{Status\[w(\d+)%\|p(\w+)\|v(\w+)\|r(\d+\%)\] TG\[(\d+)\|(\d+)(?:\/(\d+\%))?\].*\[(?:(\d+\%)|(\w+))(?:\/(\d+)c)?(?:\/(\d+)c)?\]}}
[02] variable hpWorth   125
[02] variable hpProt    OFF
[02] variable hpVeil    ON
[02] variable hpRepower 47%
[02] variable hpTP      7
[02] variable hpGL      11
[02] variable hpGLBurn               <========
#VARIABLE {hpGLBurn}={NA}   <========
[02] variable hpFamHP   126%
[02] variable hpCorFam  1
[02] variable hpCorCof
#VARIABLE {hpCorCof}={NA}
[10] if {!&{hpGLBurn}}
[05] endif
[10] if {!&{hpCorFam}}
[05] endif
[10] if {!&{hpCorCof}}
[05] endif
[02] showme {STATUS:  PROT: $hpProt VEIL: $hpVeil TP: $hpTP GL: $hpGL $hpGLBurn}{3}
[02] showme {CORPSES: INV: $hpCorInv COF: $hpCorCof  FAM: $hpCorFam | EN: $hpName : $hpHealth}{1}
[02] variable hpGLBurn NA         <=========
Status[w125%|pOFF|vON|r47%] TG[7|11] Valithyn[126%/1c]
Back to top
View user's profile Send private message
oneor11



Joined: 01 May 2017
Posts: 10

PostPosted: Tue May 02, 2017 12:23 pm    Post subject: Reply with quote

I think I figured out the root cause. If I assign a variable to a %placeholder that is part of an optional regex And that regex doesn't match, then the variable is not created. If I manually assign a value to this variable, then it will report out to the screen. So as a workaround I identified the "optional" placeholders in the regex and assigned them to "optional" variables (suffixed with Opt). Then later in the code I check if those are variables. If they are I assign it to the variable I really want to use. If not, then I set the variable I want to use to an empty string. It's working well with no echoes back to the screen.
Code:

#ACTION {{HP\[(\d+)(?:\((\d+)\))?\/(\d+)\] SP\[(\d+)(?:\((\d+)\))?\/(\d+)\] NP\[(\d+)\/(\d+)\|(\d+)c\] E\[(.*?)(?::(.*))?\]}} {
        #VAR hpCurrHP           %2;
        #VAR hpInfHPOpt         %3;  #NOP optional;
        #VAR hpMaxHP            %4;
        #VAR hpCurrSP           %5;
        #VAR hpInfSPOpt         %6;  #NOP optional;
        #VAR hpMaxSP            %7;
        #VAR hpCurrNP           %8;
        #VAR hpMaxNP            %9;
        #VAR hpCorInv           %10;
        #VAR hpEName            %11;
        #VAR hpEHealthOpt       %12; #NOP optional;

        #IF {&{hpInfHPOpt}} {
                #VAR hpInfHP $hpInfHPOpt;
        };
        #ELSE {
                #VAR hpInfHP {};
        };

        #IF {&{hpInfSPOpt}} {
                #VAR hpInfSP $hpInfSPOpt;
        };
        #ELSE {
                #VAR hpInfSP {};
        };

        #IF {&{hpEHealthOpt}}{
                #VAR hpEHealth $hpEHealthOpt;
        };

        #IF {"%11" == "none"}{
                #VARIABLE hpEHealth {NA};
        };
        #SHOWME {HEALTH:  HP: $hpCurrHP/$hpMaxHP  SP: $hpCurrSP($hpInfSP)/$hpMaxSP  NP: $hpCurrNP/$hpMaxNP}{2};
        #UNVARIABLE hpInfHPOpt;
        #NOP UNVARIABLE hpInfSPOpt;
        #UNVARIABLE hpEHealthOpt;
}{1};
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Tue May 02, 2017 6:10 pm    Post subject: Reply with quote

You should use #ECHO instead of #SHOWME, because the second one can trigger other actions, like it was a line coming from the mud


EDIT:
I suppose that if you initialize the variables like this (note the brackets around the value):
Code:

#VAR hpInfHPOpt         {%3};

all your issues will go away and the variable will be created (empty) even if there's no corresponding value in the regexp
Back to top
View user's profile Send private message
oneor11



Joined: 01 May 2017
Posts: 10

PostPosted: Tue May 02, 2017 7:25 pm    Post subject: Reply with quote

PowerGod wrote:
You should use #ECHO instead of #SHOWME, because the second one can trigger other actions, like it was a line coming from the mud


EDIT:
I suppose that if you initialize the variables like this (note the brackets around the value):
Code:

#VAR hpInfHPOpt         {%3};

all your issues will go away and the variable will be created (empty) even if there's no corresponding value in the regexp


Man you solved all of my problems in the universe. This is a very eloquent approach and cleaned up my code 10 fold. And the echo is really nice because not only does it honor the split lines, it comes built in with a format, making the coloring more clean. THANK YOU!!
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed May 03, 2017 6:56 am    Post subject: Reply with quote

Thumbs Up

Maybe you can also have a look at #PROMPT command, it doesn't put values in variables, so you still need the #action for that (if you need those variables for something else), but it's main purpose is to catch the mud prompt and show it as you want it to be, and by default it is put on the split line.

You can use the same regexp of the action for it.
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