Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
haardo
Newbie


Joined: 10 Feb 2007
Posts: 5

PostPosted: Tue Feb 13, 2007 9:24 am   

Using %random() to read file...
 
Hey all.

I'm having some odd problem with my little thingie I made.

At the moment I have triggers set up so that once there's some chat going on a specific channel my client captures the line and saves it to a text file. Then, if someone says ".random" on the said channel, my client reads a random line from the text file and pastes it on the channel. Works almost as intended. Almost. The problem is that for some reason the %random() pick the line out of the first 200 or so lines and ignores the rest of the file.

Any ideas what might be up with it?

Lemme put the rest of the stuff here..

pattern:
Code:
(%x) *lahti+]:* .random

contents of the trigger:
Code:
#VAR quoterequest 1
#RESET (@randomquote)
#FILE 1 quotes.txt
#VAR randomquote %read( 1, %random( ))
lahti @randomquote


the reader/saver trigger pattern:
Code:
(%x) *lahti+]: (%x) (%x)

and then the contents of the trigger:
Code:
#VAR lainaus %line
#VAR quotereq %3
#VAR quote %2
#IF (@quoterequest = 0) {saveline} {}
#VAR quoterequest 0


and then finally the 'saveline' alias:
Code:
#FILE 1 quotes.txt
#IF (@quotereq = "[lahti+]:") {} {#WRI 1 @lainaus}
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Feb 13, 2007 10:24 am   
 
Why does %random have no parameters? You need to specify at least the maximum value for it to choose from:

#VAR randomquote %read( 1, %random(%filesize(1)))
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
haardo
Newbie


Joined: 10 Feb 2007
Posts: 5

PostPosted: Tue Feb 13, 2007 1:11 pm   
 
Well I didn't put any parameters since the file line amount was increasing all the time, so a fixed amount would be quite useless, AND I'm not a pro with this stuff yet. :) Just started fiddling with the thing the other day.
Reply with quote
haardo
Newbie


Joined: 10 Feb 2007
Posts: 5

PostPosted: Tue Feb 13, 2007 3:19 pm   
 
As you can probably tell, the code also prohibits itself from writing the line which is retrieved from the file again into the same file. But with that there's also a slight oddity. If someone requests the .random quote on the channel too quickly, occasionally the quoted lines are added into the file anyway. I've tried all kinds of things (within my knowledge) but I can't seem to get rid of this problem. Ideas?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Feb 13, 2007 3:51 pm   
 
It'd help if we had some examples of the input that these triggers are recieving. For now, though, the easiest way would be to add a check to the trigger that looks something like this:

#if (!%pos(".random",%1) {save}

You could even use a single trigger for both operations:

Pattern
(%x) *lahti+]: (%x) (%x)
Script
#if (%pos(".random",%line)) {read a random line from the disk} {save the line to the disk}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
haardo
Newbie


Joined: 10 Feb 2007
Posts: 5

PostPosted: Tue Feb 13, 2007 4:34 pm   
 
Allright I'll try that.

In the meanwhile, here's an example:

Code:
Haardo {lahti+}: Yoz {lahti+}: emmä rippii paskempaa muistaaksee lyöny!


There we have a line which I would not want to get into the file again since it's a quote already.

And a normal chat line which should be saved looks like this:

Code:
Haardo {lahti+}: emmä rippii paskempaa muistaaksee lyöny!


And just for addition, []'s on the channel name are used when non-opped person talks and {}'s when it's an operator. I was fighting with the patterns because of this as the trigger code for some reason wanted to consider the brackets as part of the code and not the pattern, causing initially a load of grayed hair and smashed keyboards, but I finally managed to work around it with using wildcards and only one of the brackets visible in the trigger.

Code:
(%x) *lahti+]: (%x) (%x)



---------
EDIT:

Thanks guys it works perfectly now. :)
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Feb 14, 2007 1:00 am   
 
In answer to your bracket woes, just for future reference - the brackets are special characters, you need to escape them with ~ so that CMUD knows you're using them as literal characters. You can then do something like this:

{~{|~[}lahti{~}|~]}
or
[~{~[]lahti[~}~]]

to match either kind of bracket.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
haardo
Newbie


Joined: 10 Feb 2007
Posts: 5

PostPosted: Wed Feb 14, 2007 3:04 am   
 
Oh right. Thanks again, gotta keep that in mind.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net