Math

Need some help with your MUD client? Forgot your password? Get help here.
Forum rules
- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.
Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

Re: Math

Post by Kwevin » 26 May 2017 07:50

Okay, took a bit for an amateur, but here's what I got.
My idea is, alias or trigger, input in coppers. Like, <estimate 3500>
How's this look?

Code: Select all

var copp = regexp
var min = 12;
var silv = Math.floor(copp/min);
var srem = Math.floor(%copp/min);
var copp = Math.floor(copp+srem);
var gold = Math.floor(silv/min);
var grem = min%silv;
var silv = Math.floor(silv+grem);
var plat = Math.floor(gold/min);
var prem = min%gold;
var gold = Math.floor(gold+prem);
gwc.output.append(plat + " plats.");
gwc.output.append(gold + " gold.");
gwc.output.append(silv + " silvers.");
gwc.output.append(copp + " coppers.");
Would be cooler, if I could get it to do exactly what the bank does, i.e. estimate 30(c), 27(s), 90(g), 200 to come out with a full minimize. So it's easier to know exactly how much money you have.
Last edited by Kwevin on 26 May 2017 08:47, edited 1 time in total.
Alea iacta est. Serius regredi est.

User avatar
Melarec
Rising Hero
Posts: 318
Joined: 29 Feb 2016 19:51
Location: Everywhere
Contact:

Re: Math

Post by Melarec » 26 May 2017 08:18

Kwevin wrote:Okay, took a bit for an amateur, but here's what I got.

Code: Select all

var x = 60; //The regexp number to input. Kinda like an alias. 
var y = 12; //Division number.
var num = Math.floor(x/y); //Coppers reduced.
gwc.output.append(num + " silvers.");
var rem = Math.floor(y%x); //Help? Wouldn't work right!
gwc.output.append
Hmm. So that last bit.. Looks unfinished..?
Also, why are you using the percent sign to calculate "rem" ?
I'm assuming "rem" is the variable for the "remainder"
In which case, you'd want:

Code: Select all

var rem = (x - (num * 12)) //JS automatically executes math equations, right?
Assuming that "x" is the original amount of coppers, yes?
I'm not the greatest at making code fly within the game..
I'm much better at using JS inside HTML..
But you should be able to get this to work.
The way it is now, you should be able to output how many Silver coins your Coppers are worth with the number of Coppers left over.
To pump it up to Plats, you'll need a few more equations.

Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

Re: Math

Post by Kwevin » 26 May 2017 15:27

Thing is, I've got a really solid skeleton of what I want. The only thing that is stopping me is how to take the regexp number, and use that as a variable.
The % seems to work.

Code: Select all

var copp = 
var min = 12;
//Division rate^
var silv = Math.floor(copp/min);
//silvers computed
//x - num * 12
var srem = copp - (silv * min);
//remainder of coppers
var copp = srem;
//remainder of copper not into silver is now coppers
var gold = Math.floor(silv/min);
// golds computed
var grem = silv  - (gold * min);
//remainder of silvers from the gold
var silv = Math.floor(silv+grem);
//adding remainder of silvers to the gold
var plat = Math.floor(gold/min);
//gold converted to plat
var prem = gold - (plat * min);
//remainder of golds
var gold = Math.floor(gold+prem);
//adding total golds
gwc.output.append(plat + " plats.");
gwc.output.append(gold + " gold.");
gwc.output.append(silv + " silvers.");
gwc.output.append(copp + " coppers.");
//display
My apologies, Melarec. I did that portion at 2 this morning, and my copy paste was sloppy. Above is my code in full.
Last edited by Kwevin on 26 May 2017 16:00, edited 3 times in total.
Alea iacta est. Serius regredi est.

Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

Re: Math

Post by Kwevin » 26 May 2017 15:36

Update: Implemented my chunk. It works just like a shop!

7500 coppers is:
4 plats.
64 gold.
637 silvers.
0 coppers.
Aaaannnnd... 637 silver is something like 7600 copper.
Alea iacta est. Serius regredi est.

User avatar
Tarax the Terrible
Myth
Posts: 1331
Joined: 09 Mar 2010 20:33
Location: UK

Re: Math

Post by Tarax the Terrible » 26 May 2017 16:22

Good job.

Now add some nice colors...

Eg

Code: Select all

gwc.output.append("Your coloured text");
gwc.output.color("#0059B3");

Can get the hex colour codes from google
download9eef3d6f_f0_2fPictures_2fScreenshots_2fScreenshot_2017-05-26-15-17-45.png
download9eef3d6f_f0_2fPictures_2fScreenshots_2fScreenshot_2017-05-26-15-17-45.png (59.72 KiB) Viewed 2857 times
http://genesisquests.pbworks.com/
Join up and help each other with Quests :)

User avatar
gorboth
Site Admin
Posts: 2352
Joined: 03 Mar 2010 20:51
Location: Some old coffin

Re: Math

Post by gorboth » 26 May 2017 17:15

Sounds like you're having fun. :-)

G.
Mmmmmm ... pie ...

Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

Re: Math

Post by Kwevin » 26 May 2017 18:12

I am! But I need help! I wanna make this a trigger. Here's my plan.

Alias: something simple, like an output append, which triggers the trigger.

Trigger, regexp is input, instead of my specific copper count. That was test. Help with the regexp portion?
It's not done yet, by any means. But, yes, colors.

And it is horribly inaccurate.
Last edited by Kwevin on 26 May 2017 18:23, edited 1 time in total.
Alea iacta est. Serius regredi est.

Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

Re: Math

Post by Kwevin » 26 May 2017 18:18

Tarax the Terrible wrote:
Can get the hex colour codes from google
download9eef3d6f_f0_2fPictures_2fScreenshots_2fScreenshot_2017-05-26-15-17-45.png
So far, my favorite hex color supplier is http://htmlcolorcodes.com/color-names/
Alea iacta est. Serius regredi est.

User avatar
Melarec
Rising Hero
Posts: 318
Joined: 29 Feb 2016 19:51
Location: Everywhere
Contact:

Re: Math

Post by Melarec » 26 May 2017 18:43

Kwevin wrote:Update: Implemented my chunk. It works just like a shop!
7500 coppers is:
4 plats.
64 gold.
637 silvers.
0 coppers.
Aaaannnnd... 637 silver is something like 7600 copper.
Looks like you might have some recursive addition going on..
When you calculate the remainder from the next tier, it's adding that to the previous count.
So you end up with coins out of nowhere.
You should be an accountant; making money from nothing is their specialty!

If you're looking for a total, then you need to work backwards.
Calculate Plats first. Then use the remainder to calculate Gold. Then use that remainder to calculate Silver. Then the last remainder is your Copper.
What you have above is:
7500 coppers is 4 Plats. (Plus a bit, so the remainder re-adds to the Gold pile)
7500 coppers is 52 Gold. (You rounded down, so you ended up with an extra 12 from the remainder calculation.)
7500 coppers is 625 Silver. (Same as above.)
If that's what you want, excellent, just toss out the remainders.
Or, you can keep the remainders, just calculate every one of them separately and keep them in-line with the base calculation.
You would end up with something similar as below:

Code: Select all

gwc.output.append(copp + "Copper Coins is" + c2pPlats + "Platinum Coins," + c2pGold + "Gold Coins," + c2pSilv + "Silver Coins, and" + c2pCopp + "Copper Coins.");
gwc.output.append(copp + "Copper Coins is"  + c2gGold + "Gold Coins," + c2gSilv + "Silver Coins, and" + c2gCopp + "Copper Coins.");
gwc.output.append(copp + "Copper Coins is"  + c2sSilv + "Silver Coins, and" + c2sCopp + "Copper Coins.");
And you'd need to calculate all of them separately. Hence the "c2(p|g|s)" variables.
And the remainder should never be 12 or more. So, the most you could get is "x Plats, 11 Gold, 11 Silver, and 11 Copper"
You could also add a dozen "if" statements to see if each remainder is above zero and adjust the output accordingly.
You're on the right track, though!

Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

Re: Math

Post by Kwevin » 27 May 2017 00:33

Do you know of any resource I can use to debug line by line? I'm currently using Droidscript.
Alea iacta est. Serius regredi est.

Post Reply
http://tworzymyatmosfere.pl/przescieradla-jedwabne-z-gumka/