counter

ceff
Posts: 21
Joined: Thu Apr 08, 2010 11:45 pm

counter

Post by ceff »

could someone help me make a counter. say i wanted to count how many times * You think your spell casting skill has improved. * and be able to check with an easy alias like spellcasting+ or something like that

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: counter

Post by Knute »

Set up a trigger: You think your spell casting skill has improved.

You can use substring, begining of line, or exact, dependingo n where it shows up.

Your script would be something like:
Code: [show] | [select all] lua
if skillimproved == nil then skillimproved = 0 end
skillimproved = skillimproved + 1
This counter would be reset to zero when you restarted mudlet.

Your alias: ^skillimp$
Script: cecho("<white>Skills improved <gold>" .. skillimproved .. "<white> times.\n")

When you type skillimp on the command line it will say the lines in quotes in white, and your count in gold. You can change that however you like. If you just want the number then just have it echo the variable that you use.

ceff
Posts: 21
Joined: Thu Apr 08, 2010 11:45 pm

Re: counter

Post by ceff »

the trigger works, but the alias doesn't, any help? and could you make it save into a variable so that i can use it again the next time i use mudlet? and possibly have me change the score in the variable

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: counter

Post by Knute »

In order to program in any language, you need to sit down and work out the steps that you need to take.

After that is completed, you put it into pseudocode.

For this example, you need to initialize the variable, then increment it.

If you want to save it when you exit, then you need to work out those steps.

After that is completed, you would then code it.

This link will help you do that: http://mudlet.org/asciidoc/manual.html#apiIndex

If you need help with it, post the code, and we can give you pointers.
If you run into errors, you need to let us know how things went wrong. Posting something like, "It doesn't work." is of no help at all.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: counter

Post by Vadi »

+1 knute. can't really go about asking for things all day long

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: counter

Post by Knute »

hrmmm... Hey ceff, how can you tell that the trigger works if you can't see the variable?

There were no indicators written into the trigger to tell you if it fired or not.
So if the alias doesn't work, how do you know that the trigger is working?

vint
Posts: 13
Joined: Sat Jul 03, 2010 9:01 pm

Re: counter

Post by vint »

i am able to get the counter and alias working, but when attempting to save the variable im not having luck, i input another script which say that
if totalkills == nil
then bob = dailykills + bob
end
bob = dailykills
the help file doesn't make much since, the variable works, it just restarts and i've tried to send the variable to define itself as a number, but I don't understand how to do that.

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: counter

Post by Knute »

The function that you are looking for is tonumber()

So if dailykills = 8 in order to get it recognized as a number you would do
Code: [show] | [select all] lua
tonumber(dailykills)
Quick question about your script: what is the relation between totalkills and dailykills?

As for saving, you need to keep in mind that lua stores everything in tables.
So, your variables are stored in tables regardless of whether they are bob, or dailykills or generictable = { firstvalue , secondvalue = "tuna", thirdvalue = { somemore = "data"}}

Lua looks at all these as just tables, regardless of their size or what they contain.

Mudlet has a table.save function and also a table.load function.
Both functions take 2 arguments. The first argument is the file that you want to either save your files to or load them from. The second argument is the name of the table.

Now, as programmers try to make things easy, there is another function that helps out with where to save your tables: getMudletHomeDir()
This function simply returns the location on your system where the current profile is located.
If you assign a local variable (so that the variable is only accessible to the given function) to this function, then that variable will point to where all the other files are in this profile.

To use it:
Code: [show] | [select all] lua
local hmdir = getMudletHomeDir()
table.save(hmdir .. "/bob.table", bob)
This should work, but I'm not sure. I've never tried saving individual variables before, but because of the way lua stores things it should work. In order to load it, you would use table.load instead of save, but it works just the same.
Also, I am using a LINUX format for separaters, so if you are not on linux you may have to change the forwardslash (/) to a backslash (\).

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: counter

Post by Vadi »

tbh I suspect / will work fine on windows as well

vint
Posts: 13
Joined: Sat Jul 03, 2010 9:01 pm

Re: counter

Post by vint »

and are both of these aliases? or does it matter? could i make them an alias as "quit" and than in order to load them i would use some other alias like killretrieve? sorry, im not much of a programmer, still learning and i didn't understand some of that.

Post Reply