|
Cylomar Newbie
Joined: 28 Jul 2011 Posts: 2
|
Posted: Thu Jul 28, 2011 1:41 am
Variable assistance: |
Two questions. The first I think I know, but thought I'd appeal to the more experienced.
First:
How can you reference a multi-word variable?
IE: #VAR (big blue box) 0 0
Second:
I'm trying to create individual variables from a line that has a varying number of words.
If the output of the MUD is:
Extra flags: magic glow dark.
I'd like the variables to be @magic, @glow and @dark.
However, if another piece of equipment shows:
Extra flags: hum.
I'd like the same trigger (or trigger set) to be able to work regardless of how many (or how few) words I'd like to set.
Ideas/Suggestions? I'm at a loss. And my brain hurts.
Thanks in advance. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Thu Jul 28, 2011 2:14 am |
First question: putting braces - {} - around your multi-word variables should work, though really it's just recommended to not put spaces in variable names. An underscore would be a good replacement, if you want the spaces for visibility purposes.
Second question: You could use the %replace function to change the spaces into |'s, then loop through the stringlist to create variables. The code would look something like this (untested):
Code: |
#TRIGGER {^Extra flags: (*).$} {#FORALL %replace("%1"," ","|") {#VAR {%i} %null}} |
(You can change the %null to whatever you want the variables to be set to). However, if the point of this is simply to keep track of which flags are on the item, a stringlist variable would definitely be better for that. You might want to look into those. |
|
|
|
Cylomar Newbie
Joined: 28 Jul 2011 Posts: 2
|
Posted: Thu Jul 28, 2011 2:14 pm |
For the first, brackets and quotes have been tried in a number of ways to reference the variables, but it just doesn't seem to work. My thoughts are that variables with spaces cannot be referenced. But I thought I'd try.
As for the second, that worked like a charm. Hindsight being what it is, and with the new knowledge gained, it worked like a charm. Such a simple solution to my problems. Many thanks. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Jul 28, 2011 10:04 pm |
variables with spaces can be referenced, but it depends on HOW you are referencing it. Most of the time the space is going to interfere with the parsing of the arguments, or at least will require you to use extra characters or functions to such degree that it's really better overall just to not use the space in a variable name.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|