Page 1 of 1

Syntax for combining Variablenames

Posted: Mon Jan 23, 2006 4:13 pm
by Markman
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 ?

Posted: Mon Jan 23, 2006 4:16 pm
by Juutis
Try:

NAME = StringCopy(MouseSelect( true, false, 0, 0, 0, 255, 200, 200));

Posted: Mon Jan 23, 2006 4:39 pm
by Markman
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.

Posted: Mon Jan 23, 2006 6:29 pm
by Nout
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

Posted: Mon Jan 23, 2006 7:53 pm
by Markman
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");

???

Posted: Tue Jan 24, 2006 10:08 am
by Markman
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 ...

Posted: Tue Jan 24, 2006 2:08 pm
by Juutis
BTW what is the difference between
x = StringCopy(Test);
and
x = Test;

or
x = "blah";
and
x= StringCopy("blah");
Ok, I think it might be like this:
"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. :wink:

Someone more experienced please enlighten us.

Posted: Wed Jan 25, 2006 8:22 am
by Markman
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...

Posted: Wed Jan 25, 2006 7:26 pm
by Markman
... 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 ???