[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  replacing comma's

replacing comma's

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


Posted by Helpless   (48 posts)  [Biography] bio
Date Sun 23 Jun 2013 06:26 AM (UTC)

Amended on Sun 23 Jun 2013 06:27 AM (UTC) by Helpless

Message
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)
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 23 Jun 2013 10:35 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #2 on Sun 23 Jun 2013 03:27 PM (UTC)
Message
if you bothered reading what i typed, you should have seen that i tried messing with the Replace function already and failed.
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #3 on Sun 23 Jun 2013 07:19 PM (UTC)
Message
anyone out there?
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #4 on Mon 24 Jun 2013 02:44 PM (UTC)
Message
no one want to help? what i do :(
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 26 Jun 2013 08:52 AM (UTC)
Message
Quote:

If it doesn't show what you attempted.


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

Show what you attempted.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Wed 26 Jun 2013 08:55 AM (UTC)
Message
If you keep cross-posting, and ignoring my requests for more information, you will be banned.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #7 on Wed 26 Jun 2013 07:09 PM (UTC)
Message
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.
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #8 on Wed 26 Jun 2013 07:27 PM (UTC)

Amended on Wed 26 Jun 2013 07:28 PM (UTC) by Helpless

Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Wed 26 Jun 2013 11:38 PM (UTC)
Message
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>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #10 on Thu 27 Jun 2013 02:45 AM (UTC)
Message
yep...something somewhat simple i didnt try. totally called that one...thanks.
[Go to top] top

Posted by Helpless   (48 posts)  [Biography] bio
Date Reply #11 on Thu 27 Jun 2013 03:13 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Thu 27 Jun 2013 12:44 PM (UTC)
Message
No, enabling triggers is a global thing. You can check if they are enabled and warn if they are not.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


33,484 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]