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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
leonardofaoro
Novice


Joined: 07 Feb 2008
Posts: 40
Location: Italy

PostPosted: Fri Mar 21, 2008 2:17 pm   

%if check for Duplicates in Items DB
 
#DBLOAD id
%if (%numitems(%query((&name = @item.name), All))=0, #NEW all @item, #echo @item.name already in ID DB)
#DBSAVE id
#t- Identify

What's wrong with it?
Returns this error:
Error compiling script:
illegal character in expression: W
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Mar 21, 2008 4:49 pm   
 
Maybe try changing the %if function to an #if command

Code:
#if (%numitems(%query((&name = @item.name),"All"))=0) { #NEW all @item} {#echo @item.name already in ID DB}
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Mar 21, 2008 5:08 pm   
 
You can also put #CALL in front of the %if function (or any other function for that matter) to call it and discard the return value.
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Mar 21, 2008 8:34 pm   
 
But in that case, it wouldn't do anything, including running those commands.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
leonardofaoro
Novice


Joined: 07 Feb 2008
Posts: 40
Location: Italy

PostPosted: Fri Mar 21, 2008 9:22 pm   
 
Thank you man, it works perfectly now. Two quests, why use #if instead of %if ? Is there any major difference?, then why you put All in "", does it really need to be liked that?
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat Mar 22, 2008 12:09 am   
 
Try it this way:
Code:

#DBLOAD id
%if (%numitems(%query((&name = @item.name), All))=0, {#NEW all @item}, {#echo @item.name already in ID DB})
#DBSAVE id
#t- Identify

It will get rid of the syntax error. Also, since you are adding the record to the current db, and ALL is the default view,this is the customary method:
Code:

......{#NEW "" @item}......


NOTE: This is an edited post.
_________________
Sic itur ad astra.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat Mar 22, 2008 2:35 am   
 
%if is a function, #if is a command. Generally speaking, commands do things and functions return things. There're some functions that do things as well as return things, but they're comparatively rare. Functions and variables can't be the only thing on a line in CMUD, because you haven't told CMUD what to do with whatever %if returns. You need a command to tell it what to do.

#say %if(@number>10,hello,goodbye)

The %if will return "hello", not send it to the MUD, when the number is above 10. It'd be as if you typed "#say hello" on the command line. Whereas the command:

#if (@number>10) {hello} {goodbye}

will send the command "hello" to the MUD if the number is more than 10.

#say %if(@number>10,hello,goodbye)
#if (@number>10) {#say hello} {#say goodbye}

do the same thing.

EDIT: Also, Anaristos' script has a number of syntax errors. You can't begin the line with %if, it needs to be #if, and you don't need the commas after the expression's closing ) and the command's closing }.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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