declare xxx for yyy

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
Slig
Posts: 637
Joined: 15 Jun 2010, 11:52
Location: TraXicoLand

declare xxx for yyy

Post by Slig »

Hi,

Like it was a good thing to have an explanation of the = vs <=>, i guess that an explanation of the 'declare xxx for yyy = val;' would be a good thing. And both would be included (or linked) in the Gugli's Syntax basics.

All I can guess is that for example 'declare Integer TotalCaptureTime for Player' create a variable TotalCaptureTime associated/linked to the current Player object, so that if later I again do a 'declare Integer TotalCaptureTime for Player' with the same Player object then I get the same variable with the same value again ?

If that's it, what is the scope/existence of that variable ? current script ? any script running on the same game server ? any script accessing the same object, even remotely like a client maniascript UI ???

Edit: seeing a compiler message i got, the real name seems to be 'attribute'. And because they can be attached dynamically on an existing object, 'dynamic attribute' is probably a better name. Also, note that not all kind of object will accept to attach dynamic attributes.
Last edited by Slig on 16 Jul 2012, 16:13, edited 3 times in total.
User avatar
TGYoshi
Posts: 795
Joined: 15 Mar 2011, 16:59

Re: declare xxx for yyy ?

Post by TGYoshi »

That is it, as far as I know.
You can do that for every object.

I'd like to know the scope as well.
=3
User avatar
m4rcel
Posts: 650
Joined: 15 Jun 2010, 11:12
Contact:

Re: declare xxx for yyy

Post by m4rcel »

You exactly got it: With "declare X for Y", the variable X is attached to the object Y. ("dynamic attribute" is a nice name for it ^^) Whereever you have Y, you can again declare X for Y to get the (previous) value of X (so if you have the same Y, it is the same X). Y must be an object (i.e. of type C***), you cannot declare attributes for plain types like Integer or Text. And of course Y must be not Null ^^

My experiences so far is, that X get the same scrope as Y: As long as the object "lives", you have your dynamic attributes of that object. I only worked with Scripts in Manialinks so far, but I would assume, that if the object is known on the remote side, so have all its dynamic attributes as well.

But there is one trap: Be careful with initialisation vs. assignment:

Code: Select all

// Initialisation:
declare Integer I for Quad = 42; 
// I will only be set on 42, if it did not existed as dynamic attribute before.
// If I already have been declared before, it will NOT be set to 42 anymore!

// Assignment:
declare Integer I for Quad;
I = 42; // I will always be set to 42.

And there is even more behind the declare-for: The declare-as-for :D

Code: Select all

Void DoSomething(CMlQuad Quad1, CMlQuad Quad2) {
    declare Integer Color as Color1 for Quad1;
    declare Integer Color as Color2 for Quad2;
    Color1 = Color2;
}
If you have two objects with the same dynamic attributes, you can avoid name collisions by assigning a kind of alias to the attributes using "as". These aliases are only valid in the current scope, the value in the above example will still get assigned to Color of Quad1. (The syntax is a bit weird, I always think of it as "declare Integer Color for Quad1 as Color1", meaning that you still declare Color for Quad1, but want to use it as Color1 in the current scope.)
ImageImage
Image
User avatar
Slig
Posts: 637
Joined: 15 Jun 2010, 11:52
Location: TraXicoLand

Re: declare xxx for yyy

Post by Slig »

Thanks m4rcel, i already noticed that it is an initialisation and not an assignment, but it is a good thing to remind it clearly :)

And more thanks for the 'declare ... as ... for ...' info : i already was wondering about how to avoid name collisions, and it's for sure the right answer ;)
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 1 guest