Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

How to use stateitem function in scriptcards?

Hi everyone, I want to store a number using stateitem to recall it in another scriptcard. I'm not getting how it works. Maybe someone can post two lines using stateitem; write and stateitem; read? Thx in advance
1618067983
David M.
Pro
API Scripter
Never used this before, but it looks like this works. Two simple scriptcards below. The first creates a string variable "MyStr" and then stores it to the State object. The second retrieves the string variable from State, writes it to a new string variable "RetrievedStr", and prints it to chat. Store string variable: !scriptcard {{ --&MyStr|I stored this string --+String to store to State object|[&MyStr] --~MyStr|stateitem;write;stringvariable }} Retrieve string variable and print: !scriptcard {{ --~RetrievedStr|stateitem;read;stringvariable --+String retrieved from State object|[&RetrievedStr] }} Same examples, but storing a roll variable: !scriptcard {{ --=MyRoll|1d20 --+Roll to store in State object|[$MyRoll] --~MyRoll|stateitem;write;rollvariable }} Retrieving a roll variable: !scriptcard {{ --~RetrievedRoll|stateitem;read;rollvariable --+Roll retrieved from State object|[$RetrievedRoll] }} Remember, only one variable of each type (roll & string) can be stored at any one time.
Thanks David. I will give it a try!