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
Mistral
Newbie


Joined: 09 Sep 2007
Posts: 3

PostPosted: Wed Jun 29, 2011 6:23 am   

#FUNC and #LOOPDB question
 
I have a couple of questions...

1) Is there a built-in index you can use, when using #LOOPDB ? Or do I have to make a dummy variable where i add 1 each time it loops in the DB ?

2) Is there any way to prevent Zmud from writing out a functions code eg.

I have this function:

#FUNC test {#IF (%1 > 1) {#show Yes} {#show No}}


If I call it using @test(5) it will output the entire function if-sentence,
to the mud.
I just want to get the result printet on the screen ("Yes" in this case).

Is this possible or have I misunderstood something?
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Fri Jul 01, 2011 10:29 am   
 
1) I thought you might be able to use %i, but looks like you can't, so I'm leaning towards no built-in index variable...

2) You can't use commands in functions. Try this:
Code:
#FUNC test {%if(%1 > 1,"Yes","No")}

Then to display the result, you would use #SHOW @test(5).
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Fri Jul 01, 2011 10:57 am   
 
As far as 1, no you can't get an iteration count from #LOOPDB, however as the help file states it does have built in index variables of %key and %val to track those.

Code:

LOOPDB

Syntax: #LOOPDB database-rec {commands}

Loops through each key-value pair in the database variable and executes the specified commands.  When executing the commands, the variable %key contains the current key and %val contains the current value of the keyword.

LOOPDB Example

#ADDKEY db Name Zugg
#ADDKEY db Race Dwarf
#LOOPDB @db {#SHOW %key "=" %val}

Loops through the database record db and displays the key value pairs.  In this example, the result would look like:

Name = Zugg
Race = Dwarf
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Jul 01, 2011 5:10 pm   
 
If you use commands in a function, you have to wrap them in a function like %exec() that can handle commands inside them.
_________________
EDIT: I didn't like my old signature
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