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.
 Entire forum ➜ MUSHclient ➜ General ➜ jscript code help

jscript code help

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


Posted by Klintz   (5 posts)  Bio
Date Thu 07 Apr 2005 07:16 AM (UTC)
Message
First time poster long time user of MC, just started scripting for it... heres my problem, when a skill of 1 word increases everything works fine, but when a 2 or 3 word skill is set, it doesnt work.. i need somehow to create %1 to nospaces.
ps i have none to limited knowledge of jscript, so this is just to learn...

these are the two triggers.

<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="Your knowledge of * increases!"
send_to="12"
sequence="100"
variable="lastinc"
other_text_colour="black"
other_back_colour="black"
>
<send>var sInc, sInc1, sInc2, sInc3;

sInc = world.GetVariable(&quot;%1&quot;);
sInc1 = world.GetVariable(&quot;%1&quot;);

if (sInc == null)
{
world.note(&quot;Skill not found adding %1 increase 1/5&quot;);
world.SetVariable(&quot;%1&quot;, 1);
}
else
{
sInc1 = sInc * 1 + 1;
world.note(&quot;Increase: &quot; + sInc1 + &quot;/5&quot;);
world.SetVariable(&quot;%1&quot;, sInc1);
}
sInc2 = world.GetVariable(&quot;%1&quot;);
sInc3 = sInc2 + &quot;/5&quot;;
world.SetVariable(&quot;lastinc&quot;, &quot;%1 &quot; + sInc3)</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="You need to visit a master to learn more about *!"
send_to="12"
sequence="100"
other_text_colour="black"
other_back_colour="black"
>
<send>var sInc, sInc1, sInc2;

sInc = world.GetVariable(&quot;%1&quot;);

if (sInc == null)
{
world.note(&quot;Skill not found adding %1 increase 0/5&quot;);
world.SetVariable(&quot;%1&quot;, 0);
}
else
{
sInc1 = sInc1 * 1 + 1;
world.note(&quot;Gain: &quot; + sInc1 + &quot;/5 Please Visit Master&quot;);
world.SetVariable(&quot;%1&quot;, 0);
}
sInc2 = world.GetVariable(&quot;%1&quot;);
world.SetVariable(&quot;lastinc&quot;, &quot;%1 5/5&quot;)</send>
</trigger>
</triggers>
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #1 on Thu 07 Apr 2005 12:05 PM (UTC)
Message
Just use replace:
string.replace(/ /g,"_");
where string is your string (%1 in this case, or whatever you've put it into).

That will replace all spaces with underscores.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Klintz   (5 posts)  Bio
Date Reply #2 on Thu 07 Apr 2005 12:08 PM (UTC)
Message
thankyou i shall test it now =D
Top

Posted by Klintz   (5 posts)  Bio
Date Reply #3 on Thu 07 Apr 2005 03:26 PM (UTC)
Message
im getting an error,

'sInc' is null or not an object


im using sInc.replace(/ /g,"_");


how do i make sInc and object?
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #4 on Thu 07 Apr 2005 05:31 PM (UTC)
Message
Actually, It will be easier to use the mushclient replace function, you can find documentation (and an example) here:
http://www.gammon.com.au/scripts/function.php?name=Replace

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Klintz   (5 posts)  Bio
Date Reply #5 on Thu 07 Apr 2005 05:37 PM (UTC)

Amended on Thu 07 Apr 2005 05:49 PM (UTC) by Klintz

Message
the code example is



world.Note(world.Replace("go north, go east", "go", "walk", true));

if the trigger is triggered on 'Your knowledge of duel wield increases!'

how can i replace the %1 (duel wield) to make it duel_wield using this function, I can't seem to work it out yet again.



sInc = world.Replace(sInc, " ", "_", true);

???
didnt work, error below.

Type mismatch
Line in error:
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #6 on Thu 07 Apr 2005 07:01 PM (UTC)

Amended on Thu 07 Apr 2005 07:02 PM (UTC) by Flannel

Message
Are you sure sInc has a string in it?

Where in your script are you trying to do the replace?

Before you do the getvariable (and then again for the set variable?)

You could do this:
sInc = GetVariable(Replace("%1"," ","_", true));
and then the set variable would be similar.

Why do you get the same thing and set it to sInc and sInc1?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
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.


20,099 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.