replacing comma's

Posted by Helpless on Sun 23 Jun 2013 06:26 AM — 13 posts, 52,831 views.

#0
im trying to make a script to keep track of how much gold i deposit throughout the day.
the problem is the comma in the deposit amount is messing it up...i've tried messing with
the replace function and didnt get anywhere (im a newb).

<trigger
enabled="y"
match="*You deposit * coins in the bank."
send_to="12"
sequence="100"
>

<send>
money = GetVariable ("money");

if (money == null)
money = "0";
world.SetVariable ("money", parseInt (money) + %2);
</send>
</trigger>

as long as the amount i deposit doesn't have a comma, it works fine.
(my attempts to mess with Replace aren't shown here...they failed and yours
will most likely work :P)
Amended on Sun 23 Jun 2013 06:27 AM by Helpless
Australia Forum Administrator #1
This should do it:

Template:function=Replace
Replace

The documentation for the Replace script function is available online. It is also in the MUSHclient help file.



If it doesn't show what you attempted.
#2
if you bothered reading what i typed, you should have seen that i tried messing with the Replace function already and failed.
#3
anyone out there?
#4
no one want to help? what i do :(
Australia Forum Administrator #5
Quote:

If it doesn't show what you attempted.


If you are going to ignore me, I won't reply.

Show what you attempted.
Australia Forum Administrator #6
If you keep cross-posting, and ignoring my requests for more information, you will be banned.
#7
Nick Gammon said:

If it doesn't show what you attempted.


this is why i didnt show what i attempted...it lacks a comma. just seemed like an incomplete sentence to me. i only cross-posted in case people didnt check JScript section anymore.
#8
In this version, the error keeps popping up that it expected a ) in the replace line.

<trigger
enabled="y"
match="*You deposit * coins in the bank."
send_to="12"
sequence="100"
>

<send>
Replace("%2", "," "", true);

gold = GetVariable ("gold");
if (gold == null)
gold = "0";
world.SetVariable ("gold", parseInt (gold) + "%2"));

</send>
</trigger>
-------------------------------------------------

In this example, the results are from depositing 1000 coins, but first the script:

<trigger
enabled="y"
match="*You deposit * coins in the bank."
send_to="12"
sequence="100"
>

<send>
dumb = getvariable("dumb");
if (dumb == null)
dumb = "0";
world.setvariable ("dumb", Replace("%2",",","", true));

gold = GetVariable ("gold");

if (gold == null)
gold = "0";
world.SetVariable ("gold", parseInt (gold) + GetVariable("dumb"));
</send>
</trigger>

Results for both vars gold and dumb (triggering the script 3 times in a row):
01000 gold deposited.
1000 gold deposited.
5121000 gold deposited.
1000 gold deposited.
51210001000 gold deposited.
1000 gold deposited.

i've tried so many other ways and different setups than that but none
yielded what i wanted. im sure whatever im doing wrong is something small
and idiotic on my part.
Amended on Wed 26 Jun 2013 07:28 PM by Helpless
Australia Forum Administrator #9
Your second example was concatenating strings, so for example if you started with 20 coins, and got another 20 you would end up with 2020 coins. If you change it to an integer it works:


<triggers>
  <trigger
   enabled="y"
   match="*You deposit * coins in the bank."
   send_to="12"
   sequence="100"
  >
  <send>
dumb = getvariable("dumb");
if (dumb == null)
dumb = "0";
world.setvariable ("dumb", Replace("%2",",","", true));

gold = GetVariable ("gold");

if (gold == null)
gold = "0";
world.SetVariable ("gold", parseInt (gold) + parseInt (GetVariable("dumb")));
</send>
  </trigger>
</triggers>

#10
yep...something somewhat simple i didnt try. totally called that one...thanks.
#11
is there any way for plugins to work without triggers being enabled?
always wondered if i could ever have the "Enable Triggers"
box unchecked and have the plugin triggers still work.
Australia Forum Administrator #12
No, enabling triggers is a global thing. You can check if they are enabled and warn if they are not.