|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: 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 |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: 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." |
|
|
|
JQuilici Adept
Joined: 21 Sep 2005 Posts: 250 Location: Austin, TX
|
Posted: 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! |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Mar 21, 2008 8:34 pm |
But in that case, it wouldn't do anything, including running those commands.
|
|
|
|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: 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?
|
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: 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. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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 }. |
|
|
|
|
|