Page 1 of 1

Tick Trigger

Posted: 12 Apr 2016 06:08
by Kwevin
Hello all. I am clueless in the language of Java, so I need help. How would I make a tick trigger?
What would you put in the pattern?
Also, how big is the number for one second?

Re: Tick Trigger

Posted: 12 Apr 2016 14:06
by Mayobe
JS and Java are 110% separate animals. (http://stackoverflow.com/questions/2450 ... t-and-java)

Triggers in the web client cannot be set to fire on a timer (yet) without some serious fiddling around.

JS is very easy to learn as far as languages go. The W3 tutorials should be enough to get you started.

http://www.w3schools.com/js/

Note that this is a very widely used language, so it's worth picking up a bit in any case. I think someone linked you the gwc thread in your other question, which discusses the unique functionality of the Genesis web client.

What is it that you want to use a timer for? There may be a different approach that would be less work.

Re: Tick Trigger

Posted: 12 Apr 2016 15:56
by cotillion
You can easily create tick triggers.

Just create a trigger on something like 'Welcome to Genesis' to start it.
https://www.genesismud.org/forums/viewt ... ick#p22245

Re: Tick Trigger

Posted: 12 Apr 2016 16:20
by Kwevin
Oh, yeah, I found that. But, my question is, how many ticks in one second? My guess was something like 1000?

Re: Tick Trigger

Posted: 12 Apr 2016 16:54
by Melarec
Tick is measured in milliseconds, so yes 1000 is once per second.

Code: Select all

setInterval(eatHerb,5000);
function eatHerb() {
    gwc.connection.send("eat herb");
}
This will eat an herb every 5 seconds.
It may actually need something to initially set it off, though.. I've not experimented with JS in Genesis, but that would call "eatHerb" once per five seconds if this were web-design..

Attached is a clock I designed with JS.. It relies heavily on the ability to tick. Uncompress and open the "clockRun" HTML file in your browser.. Or in Notepad if you want to see the skeleton code.

EDIT: 5 seconds, not 5000..

Re: Tick Trigger

Posted: 12 Apr 2016 18:57
by Kwevin
Ahh, okay. I think I have this down pretty well.

Is there a simple way to color just one word, not the whole line?

Re: Tick Trigger

Posted: 12 Apr 2016 21:02
by Mayobe
Oh? I didn't know there was a callback timer like that. Will the functions persist outside the script execution?

Sort of complicated text coloring script:

Code: Select all

Trigger (regex): (words|or phrases|that|I'm watching|for)
gwc.output.replace(RegExp(args[1], 'g'), '<span style="background-color: red; color: lime;">'+args[1]+'</span>', true);
Less complicated:

Code: Select all

Trigger (plain): orc
gwc.output.replace(/(\s(orcs|orc)[\s|\.|,])/gi, '<span style="color: darkseagreen">$1</span>', true);

Re: Tick Trigger

Posted: 12 Apr 2016 23:18
by Melarec
Just a quick note..
Don't set a trigger's pattern to " " . (The blank space between words)
I seriously bogged down my client..