Page 1 of 2


Posted: Sat Jul 03, 2010 12:23 am
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

Re: counter

Posted: Sat Jul 03, 2010 2:01 am
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.

Re: counter

Posted: Sat Jul 03, 2010 2:28 am
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

Re: counter

Posted: Sat Jul 03, 2010 12:48 pm
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:

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.

Re: counter

Posted: Sat Jul 03, 2010 1:31 pm
by Vadi
+1 knute. can't really go about asking for things all day long

Re: counter

Posted: Sat Jul 03, 2010 2:25 pm
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?

Re: counter

Posted: Sat Jul 03, 2010 10:00 pm
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
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.

Re: counter

Posted: Sun Jul 04, 2010 12:14 am
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
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 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() .. "/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 (\).

Re: counter

Posted: Sun Jul 04, 2010 1:47 am
by Vadi
tbh I suspect / will work fine on windows as well

Re: counter

Posted: Sun Jul 04, 2010 8:52 pm
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.