Author Topic: Store CMDSEGMENT:1 to a variable?  (Read 1025 times)

StuntPanda

  • Newbie
  • *
  • Posts: 3
Store CMDSEGMENT:1 to a variable?
« on: June 17, 2022, 06:52:13 PM »
I'm trying to get a command segment saved to a variable so I can manipulate it. When doing simple debugging steps to verify values I can't even get them to print in the log. I'm sure I'm making some silly mistakes but after reading the docs and several posts (including the stickied ones) I just can't figure out what I'm doing wrong.

Here's the command:
Code: [Select]
Set small int (condition) [SmallValue] value to the value of [{CMDSEGMENT:1}]
Set integer [IntegerValue] value to the value of [{CMDSEGMENT:1}]
Write [Blue] 'Small Value = {SMALL:SmallValue}' to log
Write [Blue] 'Integer Value = {INT:IntegerValue}' to log
Write [Blue] 'CMDSEGMENT:1 = {CMDSEGMENT:1}' to log

And the output:
Code: [Select]
8:39:04.676 CMD = computer value 6
8:39:04.674 CMDSEGMENT:1 = 6
8:39:04.672 Integer Value =  Not set
8:39:04.670 Small Value =  Not set
8:39:04.654 Recognized : 'computer value 6'

Thank you in advance for your help.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Store CMDSEGMENT:1 to a variable?
« Reply #1 on: June 17, 2022, 07:02:21 PM »
What it looks like you're trying to do is set the value of your integer to a variable that is resolving to the name of, '6'.  Since there is no variable called, '6', it results in 'Not set'. 

You'll want to select the option 'Convert Text/Token' and put, '{CMDSEGMENT:1}' in that box (see attached).

Hope that helps!

StuntPanda

  • Newbie
  • *
  • Posts: 3
Re: Store CMDSEGMENT:1 to a variable?
« Reply #2 on: June 18, 2022, 05:46:23 PM »
Thank you, that's great info and explains what I was doing wrong and will help me understand better how to do this stuff in the future.

Last night I forced it to work by changing it from setting the variable to another variable to setting it to a converted text/token, but I didn't understand the issue until you explained it.

I was overthinking the "Set to another variable" option. I just needed to type in the variable name. I did an unnecessary TXTNUM conversion.

I went from this:
Code: [Select]
Set integer [IntegerValue] value to the value of [{CMDSEGMENT:1}]

To this:
Code: [Select]
Set integer [IntegerValue] value to the converted value of {TXTNUM:"{CMDSEGMENT:1}"}

Which worked but was unneeded and added complexity.

The proper way (I think) is:
Code: [Select]
When I say Computer test [1..100]
Code: [Select]
Set integer [InputValue] value to the converted value of {TXTNUM:"{CMDSEGMENT:1}"}
Write [Blue] 'InputValue: {INT:InputValue}' to log
Set integer [NewValue] value to the value of [InputValue]
Write [Blue] 'NewValue: {INT:NewValue}' to log

Which results in the output:
Code: [Select]
7:42:25.882 NewValue: 33
7:42:25.878 InputValue: 33
7:42:25.872 Recognized : 'computer test 33'

Thanks again for the help! I'm clearly still trying to learn all this stuff so your reply was a huge help.