I try to use the new feature of RF, that Variables can be used across different Scripts.
I read the szEntityName of the Targeted Pawn with
NAME = MouseSelect( true, false, 0, 0, 0, 255, 200, 200);
into the Variable "NAME".
Now I want to use this Variable to read further Variables and Arrays from that Pawn with:
X = NAME.PAWN_ATTR[1].VAL
or show the Value as Message with:
ShowText(1, NAME, "", NAME.PAWN_ATTR[1].VAL, 9, "", 24, 35, "Right",
180);
But this does not work, instead of NAME.* i would have to write the exact szEntityName. But I want to keep it variable......
How does the correct Syntax look like ?
Syntax for combining Variablenames
Wow, this was fast ! ;)
I tried this, but i think the problem arises, when i COMBINE the Variable with the Array ...?
The Array is defined in the Script of Pawn "Pawn01".
So
X = NAME.PAWN_ATTR[1].VAL;
would be written
X = Pawn01.PAWN_ATTR[1].VAL;
if I knew the name of the Pawn beforehead and would want to keep that statically. But it should keep variable.
I tried this, but i think the problem arises, when i COMBINE the Variable with the Array ...?
The Array is defined in the Script of Pawn "Pawn01".
So
X = NAME.PAWN_ATTR[1].VAL;
would be written
X = Pawn01.PAWN_ATTR[1].VAL;
if I knew the name of the Pawn beforehead and would want to keep that statically. But it should keep variable.
The pawn commands expect a string
NAME.PAWN_ATTR[1].VAL is not recognized because the "NAME" part is not translated into the value assigned to NAME
A way that will work, but is not so elegant, is something like
If (NAME = "Name1") then MyName = Name1.PAWN_ATTR[1].VAL
If (NAME = "Name2") then MyName = Name2.PAWN_ATTR[1].VAL
If (NAME = "Name3") then MyName = Name3.PAWN_ATTR[1].VAL
Etc...
And finally use MyName in the commands
NAME.PAWN_ATTR[1].VAL is not recognized because the "NAME" part is not translated into the value assigned to NAME
A way that will work, but is not so elegant, is something like
If (NAME = "Name1") then MyName = Name1.PAWN_ATTR[1].VAL
If (NAME = "Name2") then MyName = Name2.PAWN_ATTR[1].VAL
If (NAME = "Name3") then MyName = Name3.PAWN_ATTR[1].VAL
Etc...
And finally use MyName in the commands
hmmm, I hardly can't believe that.
There must be a Syntax to handle the content of a String as the String itself...
BTW what is the difference between
x = StringCopy(Test);
and
x = Test;
or
x = "blah";
and
x= StringCopy("blah");
???
There must be a Syntax to handle the content of a String as the String itself...
BTW what is the difference between
x = StringCopy(Test);
and
x = Test;
or
x = "blah";
and
x= StringCopy("blah");
???
Last edited by Markman on Tue Jan 24, 2006 12:18 pm, edited 1 time in total.
Whats strange :
If I use
... Pawn01.PAWN_ATTR[1].VAL
everything is OK. But :
Pawn01 = "xyz";
... Pawn01.PAWN_ATTR[1].VAL
the same query does not work. So there seems to be be some kind of Value-Checking.
The Interpreter is NOT thinking this would be a clearly written command and is trying to use Pawn01 as a Variable.
[EDIT: The Problem is the opposite, what I learned now. You can't combine the query with Strings (wich contain Text) - you have to use Objects...!
But how to convert Strings into Objects...?]
If i try to set
Pawn01 = "Pawn01";
it also doesn't work...
If I don't assign a Value to Pawn01 (which in fact is a szEntityName) and try to display the Value of Pawn01 I get an empty String...
I don't use the Attribute-System because I want to read the Attribute-Names too. Is there any other way to read the Attribute-Names of the Attribute a Pawn carries ?!?
The Concept is, that the Player should not know before, which Attributes there are and also to display only the ones that are used, with Names.
I don't want to use H U G E IF-Lists and would prefer the way with Variables rather than with the Attribute-System.
With the above IF-Example, I not only have to define the query for every Pawn but also for every Attribute that that pawn COULD carry.
In other Languages it IS possible to construct a array-query with Variables in one single line.
... help ...
If I use
... Pawn01.PAWN_ATTR[1].VAL
everything is OK. But :
Pawn01 = "xyz";
... Pawn01.PAWN_ATTR[1].VAL
the same query does not work. So there seems to be be some kind of Value-Checking.
The Interpreter is NOT thinking this would be a clearly written command and is trying to use Pawn01 as a Variable.
[EDIT: The Problem is the opposite, what I learned now. You can't combine the query with Strings (wich contain Text) - you have to use Objects...!
But how to convert Strings into Objects...?]
If i try to set
Pawn01 = "Pawn01";
it also doesn't work...
If I don't assign a Value to Pawn01 (which in fact is a szEntityName) and try to display the Value of Pawn01 I get an empty String...
I don't use the Attribute-System because I want to read the Attribute-Names too. Is there any other way to read the Attribute-Names of the Attribute a Pawn carries ?!?
The Concept is, that the Player should not know before, which Attributes there are and also to display only the ones that are used, with Names.
I don't want to use H U G E IF-Lists and would prefer the way with Variables rather than with the Attribute-System.
With the above IF-Example, I not only have to define the query for every Pawn but also for every Attribute that that pawn COULD carry.
In other Languages it IS possible to construct a array-query with Variables in one single line.
... help ...
Last edited by Markman on Wed Jan 25, 2006 9:03 am, edited 2 times in total.
Ok, I think it might be like this:BTW what is the difference between
x = StringCopy(Test);
and
x = Test;
or
x = "blah";
and
x= StringCopy("blah");
"x = Test" changes the value of x to the value of variable Test (If Test is numerical) but if Test is string it does nothing (I believe...).
"x = StringCopy(Test)" copies the contents of string Test to x.
"x = "blah"" .... I haven't tested this much but i think it does nothing...
"x = StringCopy("blah")" assigns the string blah to the variable x.
I'm sorry for my bad english and/or wrong terms but I really can't explain these things in english properly.
Someone more experienced please enlighten us.
Pain is only psychological.
OK, I learned today (and night) that the right term would be
"OBJECT".
So the barrier is when it is tried to use a Variable with eg. a Text as content. The content must be a Objekt (-name) !
So what is needed is a Syntax to convert a String into a Object.
Something like ObjectCopy(NAME); or any other Trick, that does the same in effect... !
I don't think that this would be a too unusual thing to do.
...h.e.l.p...
"OBJECT".
So the barrier is when it is tried to use a Variable with eg. a Text as content. The content must be a Objekt (-name) !
So what is needed is a Syntax to convert a String into a Object.
Something like ObjectCopy(NAME); or any other Trick, that does the same in effect... !
I don't think that this would be a too unusual thing to do.
...h.e.l.p...
... or even stranger :
when I test what type is NAME with isObject(NAME) the Interpreter tells me it IS already an Object (= true).
So I found out "self." is its own Data-Type and the chance is high that NAME has to be of type self to be used in a query like
NAME.PAWN_ATTR[1].VAL !
Even for simpler situations this is necessary.
Here in the Forum I saw an example with self.target_name.HEALTH to get the variable HEALTH from another, targetted pawn.
This does NOT work ! You can display the name with debug(self.target_name) but if you want to get a variable with self.target_name.HEALTH you get NOTHING.
So the question may be:
How do I convert Variables into the type self ???
when I test what type is NAME with isObject(NAME) the Interpreter tells me it IS already an Object (= true).
So I found out "self." is its own Data-Type and the chance is high that NAME has to be of type self to be used in a query like
NAME.PAWN_ATTR[1].VAL !
Even for simpler situations this is necessary.
Here in the Forum I saw an example with self.target_name.HEALTH to get the variable HEALTH from another, targetted pawn.
This does NOT work ! You can display the name with debug(self.target_name) but if you want to get a variable with self.target_name.HEALTH you get NOTHING.
So the question may be:
How do I convert Variables into the type self ???