Figuring age?

Post Reply
ella
Posts: 33
Joined: Sun Feb 28, 2010 5:46 pm

Figuring age?

Post by ella »

the mud I am playing dosent tell you your age, just gives you the date of birth and another command for the current date. is there some way I can get mudlet to calculate my age for me without making to much noise?

daemoen
Posts: 7
Joined: Wed Jul 14, 2010 8:09 pm

Re: Figuring age?

Post by daemoen »

Without showing us some output, no chance :)

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Figuring age?

Post by Yetzederixx »

daemoen is correct, we'll need a sample birth date, current date, and the calendar scheme to to do anything.

ella
Posts: 33
Joined: Sun Feb 28, 2010 5:46 pm

Re: Figuring age?

Post by ella »

sorry, apparently I was just ignorant to the correct command.

I would still like to know the commands for making mudlet do math though

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Figuring age?

Post by Iocun »

You make Mudlet do math simply by using mathematical operators.

If you write in your script echo(2*(3+5/4)), it will evaluate just that and output the result 8.5
The same works with variables of course. So you could write in a script:
Code: [show] | [select all] lua
apples = 3
oranges = 5
fruit = apples + oranges
hungry_people = 4
echo("If we divide our food evenly, every hungry person gets "..(fruit/hungry_people).." fruit for dinner!")
If you want to use some extended mathematical operations, you may have too look at Lua's math library.

For instance:
echo("The sine of pi/2 is "..math.sin(math.pi/2))

ella
Posts: 33
Joined: Sun Feb 28, 2010 5:46 pm

Re: Figuring age?

Post by ella »

NEAT! thank you very very much!

but just to make sure I do this right maybe you could help me with my first one?
(5*C)/T
so I will need 5 apples per person and then I want to subtract it by the number of apples I already have to see how many I need or dont need?

and I want to be able to grab the amount of apples I already have and the people im feeding from the game

Casimar
Posts: 22
Joined: Sun Nov 07, 2010 3:47 pm

Re: Figuring age?

Post by Casimar »

http://lua-users.org/wiki/MathLibraryTutorial has all the math functions you can use. Particular favourites of mine are floor and random... Hope they help!

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Figuring age?

Post by Iocun »

ella wrote:NEAT! thank you very very much!

but just to make sure I do this right maybe you could help me with my first one?
(5*C)/T
so I will need 5 apples per person and then I want to subtract it by the number of apples I already have to see how many I need or dont need?

and I want to be able to grab the amount of apples I already have and the people im feeding from the game
Let's say your game displays the following two lines:
You are currently holding 22 apples.
You must feed 7 people.
Now you want to capture those two lines with triggers and store the amount of apples you have and the amount of people you need to feed. Then, when you type in "calculate apples", you want Mudlet to calculate how many apples you still need if you want to give everyone 5 apples, then display this number on screen.

First trigger (regular expression):
^You are currently holding (\d+) apples\.$
Executes:
my_apples = matches[2]

matches[2] refers to whatever the first wildcard in brackets () captures in that trigger. In this case, the number represented in the trigger by (\d+). Since the game displays, per above, "You are holding 22 apples.", this will set your variable my_apples to 22.

Second trigger (regular expression):
^You must feed (\d+) people\.$
Executes:
people_to_feed = matches[2]

This works exactly like the trigger above.

Now you create an alias to check how many apples you still need:
Alias pattern:
^calculate apples$
Executes:
Code: [show] | [select all] lua
apples_required = 5*people_to_feed
apples_still_needed = apples_required - my_apples
echo("I still need to gather "..apples_still_needed.." apples.")
Of course you could just shorten this to a single line, without needing the extra variable "apples_still_needed":
Code: [show] | [select all] lua
echo("I still need to gather "..(5*people_to_feed - my_apples).." apples.")
In both cases, typing "calculate apples" should display the following thing on screen:
I still need to gather 13 apples.

Post Reply