AI Zone Admin Forum Add your forum

Chatbot Conference London On Oct 3th Erwin will be moderating on the Chatbots conference in London. Why don't you meet him there? As a visitor, you'll get a discount as well: Why don't we meet there? get a discount

We do experience some trouble with our forms and some details page. We'll fix this ASAP. Sorry for the inconvenience!
Getting the value of an argument via ^argument(n)


I’m just starting to learn ChatScript, and I haven’t found a solution to a problem I’m having trying to use ^argument(n) from within an outputmacro to loop through all its arguments.

outputmacro: ^testmacro variable ( ^arg1 ^arg2 ^arg3 ^arg4 )
= ^argument($_argIndex)
code using that value...
$_argIndex += 1

^argument($_argIndex) will return matching variables _0 to _3 for $_argIndex = 1 to 4.

However, I couldn’t find a way to read the value of _0 rather than the matching variable name. I have tried ^$_argValue to no avail.

Enabling :trace all gives me:

System call ^argument(`1`)
NOPROBLEM ^argument(1) => `_0`
$_argvalue = ^argument(_0)
System call ^return(`$_argvalue`)
ENDCALL ^return(_0) => `_0

How should I proceed if I want to use the value of an argument within the outputmacro itself?

Apologies in advance if this is answered in the docs, I did do my research and came out empty.
Thank you

EDIT: I should note that when accessing _0 directly (in a comparison for instance, or logging something like ^“value is: _0”) I get the value of that argument just fine.


  [ # 1 ]

I figured out a workaround for now. I just parse an active json string containing all arguments into an array so I can iterate through it the same way I would iterate through them with ^argument. Not very elegant though as I have to edit the json string to match the arguments

$_argIndex 0
= ^jsonparse( ^"[ ^arg1 ^arg2 ^arg3 ^arg4 ]" )
$_length = ^length$_args )

loop$_length )
# ... same code as before using $_argValue
$_argIndex += 1

I’m assuming I’d need to wrap the variable in two layers of active strings so $_argValue can become ^“_0” on the first evaluation then the actual value on the 2nd evaluation. I don’t know how though.

I did manage to get the right value printed out, but it’s because it was going through a custom log method which would use the argument passed to it within an active string, doing exactly what I describe above. ^logvalue(^”$_argValue”) would work because in ^logvalue it’d do something like ^log( OUTPUT_ECHO, ^”^arg”)

If anyone has a code snippet of a successful usage of ^argument(n) I’d love to see that.

EDIT: Another workaround is to run the variable through an outputmacro that returns the active string containing the argument passed to it:

outputmacro: ^testmacro( ^arg )
  ^return( ^
"^arg" )

# ...
outputmacro: ^testmacro2( ^arg1... )
= ^argument(1)
$_test = ^testmacro( ^"$_t)
logOUTPUT_ECHO ^"$_test\n)



  [ # 2 ]

The following code worked for me:

outputmacro: ^test( $_t1 $_t2 $_t3)

topic: ~INTRODUCTIONS keep repeat (~emogoodbye ~emohello ~emohowzit name here )

t: Greetings
u: (test) ^test(1 2 3 )


  [ # 3 ]

I went back to the basics like your example and realized my problem comes from the fact that I call that macro with the matching variables from a pattern as arguments


u: (test _~number _~number _~numberResult:  ^test_0 _1 _2 

^argument(1) returns ‘_0’ and I have to play tricks with active strings to get the value out of it (as described in previous posts)


u: (test _~number _~number _~numberResult:  ^test1 2 3 

^argument(1) returns 1


u: (test _~number _~number _~numberResult:  ^test( ^"_0" ^"_1" ^"_2" 

^argument(1) returns 1

I guess I’m still a bit confused about how variable references vs. values work in ChatScript, I guess _0 doesn’t automatically print out its value because it’s in a macro call, not directly in the output.

Thanks for your help!


  [ # 4 ]

Its a CS bug. will fix for next release.


  login or register to react