SWC LISP/Debugging and Errors
Contents
- 1 Debugging Functions
- 2 Understanding Errors
- 2.1 Symbol [name] is not defined!
- 2.2 Symbol -> is not defined!
- 2.3 Symbol is undefined and cannot be evaluated
- 2.4 Invalid speech option selected
- 2.5 Attempted to evaluate a literal value or a null: "somestring"
- 2.6 Not enough arguments supplied in function call
- 2.7 `set-var!` can only be called on *vars
Debugging Functions
dbg-break
triggers an exception (ignoring the rest of the script) and print supplied values, for example(dbg-break self character (+ 1 2))
will display info about the current entity, current character, and the number 3- note that if you put
(dbg-break)
in the global scope (a line on its own), it'll block the whole script at startup. Instead, you must use it inside another function, in the point where you want the script to stop.
- note that if you put
dbg-pp
prints values for debugging without triggering an exception (script continues), using the same semantics asdbg-break
dbg-env
dumps the entire symbol table (very large) and can be used to get basic information about the API to help with missing documentationdbg-rp
provides low-level view of data structures
Understanding Errors
Most often, if you get an error it is a problem of parenthesis. When you save the script, the parser checks only for matching parenthesis; however, if the total of open parenthesis matches the total of closed parenthesis, the parser reports no errors on saving.
Symbol [name] is not defined!
If you get this error while the script runs, it could mean that there are misplaced parenthesis. In this case, go through your script placing your cursor on the end parenthesis to see if everything is ok.
If the error is not due to misplaced parenthesis, check that the name is not mispelt. If ok, check that the call to the function comes before the function called.
Symbol -> is not defined!
It is the easiest to fix. You've just written a "->" in an add-response function, between the end of text and the name of the function to go to. The old system used that symbol, but the new system need not that. Just remove that "->".
A second case is if you've added a parameter to the describe function different from close. Example, the old 'left alignment keyword, now invalid.
Symbol is undefined and cannot be evaluated
You've probably forgotten to specify where to go after an add-response text. Simply add the name of the function to continue with.
Mind the parenthesis if you have a concat function in add-response or other function with parameters. Example, this code is right:
(defun start (say "Hello, how may I help you?") (cond [(eq? (get-race character) "Kuati") (add-response "Excuse me, your dress is very elegant. May I know what caste are you?" caste01)] [(not (eq? (get-race character) "Kuati")) (add-response (concat "I see you are a " (get-infofield self) ". What do you do, exactly?") do01) (add-response "Are you a real expert on ships?" expert01) (add-response "Very kind of you, but I am just browsing. No need for help." end01)]))
but if you write the add-response with the concat function as
(add-response (concat "I see you are a " (get-infofield self) ". What do you do, exactly?" do01))
you get this type of error, because the closing parenthesis of the concat function must go after the string end and before the next-function-name parameter.
Symbol set-var is undefined and cannot be evaluated
The correct syntax is set-var! (with the 'bang') and not set-var or setvar. Check your syntax.
Invalid speech option selected
This is a generic error, meaning that any thing wrong in the next-function-name called by the user click may cause this error. A syntax error, a logic error... Below you find some examples. Note that this error appears when you try to click on an answer, therefore you should look for the function called by that answer. You can use the (dbg-xx) functions in the functions called by the add-action/add-response/add-text to check your code for unexpected evaluation results.
- If you're trying to concatenate a text with a describe, you'll get this error. Example:
(say (concat "Well, another protocol droid you can see here is the SP-4. It is defined as an analysis droid and it uses the same chassis and many parts assembled in the cheaper PK-series worker droid. You cannot say that it is made to resemble its owner..." (describe "winks")))
The solution is to put the describe in a single line, all alone, and remove the concat in the say function. `concat` only assembles several strings into one string. `describe` is a function that does not evaluate to a single string, and so concat cannot make proper use of it.
- A conditional statement with a wrong use of keywords:
(eq? (get-entity-faction character) "Galactic Empire")
is bugged;
(eq? (get-name (get-entity-faction character)) "Galactic Empire")
is correct.
- Adding a missing [#t] to a conditional statement.
Attempted to evaluate a literal value or a null: "somestring"
One possible case is that you are trying to call a function that needs a parameter from inside an add-response function. As of Y19D270, add-response can only call simple functions, without parameters.
In order to solve this problem, you should make an intermediate function. Example:
(add-response "Please forward this parameter." (intermediate-fun)) (defun intermediate-fun (get-parameter "Here is the parameter")) (defun (get-parameter thisparameter) code code code)
Not enough arguments supplied in function call
You have called a function that is expecting one or more parameters, but you have not specified any parameter.
Solution: add the parameters needed.
`set-var!` can only be called on *vars
wip