Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access to the variable in object macro after just defining the variable #137

Open
ghost opened this issue Dec 20, 2019 · 2 comments
Open

Comments

@ghost
Copy link

ghost commented Dec 20, 2019

# in python

> object tempCall python
   return 'right'
< object

< object test python

   temp_query = rs.get_uservar(rs.current_user(),"temp_query")
   print(temp_query)

> object

# in rivescript

+ xyz (x|y|z)
- <set temp_query=answer is <call>tempCall <star></call>
^ <call>test</call>

Output:
answer is {_call_}tempCall x{_call_}

I was hoping for 'answer is right' as an output.

How do I make it work? Am I missing something? Please guide me. Thanks!

@kirsle
Copy link
Member

kirsle commented Jan 4, 2020

- <set temp_query=answer is <call>tempCall <star></call>

Unfortunately, this syntax doesn't work; the <call> tag is the very last one processed after tags like <get> and <set> had already been handled.

However, you can set user variables from inside the object macro itself as a workaround:

> object tempCall python
    rs.set_uservar( rs.current_user(), "temp_query", "right")
< object

+ xyz (x|y|z)
- <call>tempCall <star></call>

Background: tags are processed using regular expressions and are done in a certain order. The only set of tags that can be nested in arbitrary order are the variable-setter tags like <get>, <set>, <add> and so on; but that's because each of those tags conveniently starts and ends with <angle brackets> so a recursive regexp can handle them from inner-most to outer-most. But tags like <call>...</call> have inner contents and would be more tricky to handle that way.

@ghost
Copy link
Author

ghost commented Jan 6, 2020

Thank you for your response! I'll check it out and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant