jscript code help

Posted by Klintz on Thu 07 Apr 2005 07:16 AM — 7 posts, 29,024 views.

#0
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>
USA #1
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.
#2
thankyou i shall test it now =D
#3
im getting an error,

'sInc' is null or not an object


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


how do i make sInc and object?
USA #4
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
#5
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:
Amended on Thu 07 Apr 2005 05:49 PM by Klintz
USA #6
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?