Set declaration madness

More
20 years 4 months ago #11172 by MajorTom
Replied by MajorTom on topic Set declaration madness

Originally posted by Second Chance

Here's your problem right here:

pos1 = iMapEntity.FindByName("Lucrecia's Base");

You can't assign a value to a variable during declaration.


You can assign a variable during declaration. You just have to declare the variable type first:

hmapentity pos1 = iMapEntity.FindByName("Lucrecia's Base");


and for example even 'cast' to a different type:

hsim pos1 = iSim.Cast ( iMapEntity.FindByName("Lucrecia's Base"));

Works using sets and lists too:

list port_list = List.FromSet ( iDockport.DockportsOfType ( iSim.Cast ( turret_ship ), DT_Cargo, DS_Free ) );



Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.

More
20 years 4 months ago #11173 by EricMan64
Replied by EricMan64 on topic Set declaration madness
Yes, assigning values during declaration is perfectly fine. The problem here is that all declarations must be made at the beginning of a function or task. Once you do something that is not a declaration, you cannot declare anything more. Assigning a value is not a declaration, so unless it is done on the same line as a declaration, there can be no more declarations after that point.

I'm not sure if I'm being very clear, so here are bad and good examples:
Code:
hmapentity pos1; hship player_ship; hship marauder1; hfaction marauder_faction; pos1 = iMapEntity.FindByName("Lucrecia's Base"); set local_fighters; // This is the set
This does not work because pos1 = ... is not a declaration. You cannot declare anything after that point, so set local_fighters does not work.
Code:
hship player_ship; hship marauder1; hfaction marauder_faction; hmapentity pos1 = iMapEntity.FindByName("Lucrecia's Base"); set local_fighters; // This is the set
This would work because everything is a declaration. Until the first non-declaration line of code for the function, you can keep declaring stuff all you want.

Please Log in or Create an account to join the conversation.

More
20 years 4 months ago #11174 by lo-tekk
Replied by lo-tekk on topic Set declaration madness

Originally posted by EricMan64

Yes, assigning values during declaration is perfectly fine. The problem here is that all declarations must be made at the beginning of a function or task. Once you do something that is not a declaration, you cannot declare anything more. Assigning a value is not a declaration, so unless it is done on the same line as a declaration, there can be no more declarations after that point.


That's a perfect explanation. It seems this threat becomes a fine beginners guide to pog - coding. :)

Please Log in or Create an account to join the conversation.

More
20 years 4 months ago #11177 by Second Chance
I plead the 5th.

No wait, even better; I plead that it was 5am when I wrote that.

Now it's 3pm. I just woke up, and my head hurts.

That my story, and I'm sticking to it. :p

Where's the water? [xx(]

mailto:second_chance@cox.net
The Ultimate Guide To Modding: I-War 2 - Edge Of Chaos (on hold during SW MP mod)
cartoons.sev.com.au/index.php?catid=4
.

Please Log in or Create an account to join the conversation.

More
20 years 4 months ago #11187 by MajorTom
Replied by MajorTom on topic Set declaration madness

Originally posted by Second Chance



That my story, and I'm sticking to it. :p


LOL Whats the problem? You were right, I was right and EricMan too.
EricMans explanation was the best for a pog beginner. I think he would make a good teacher/lecturer someday [8D];)

We are so deep into the stuff we take too much for granted.

lo-tekk, we're glad to see a new pogger around :D



Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.

More
20 years 4 months ago #11190 by Second Chance
:D Oops. I wasn't in much better shape when I wrote that post then when I wrote the first one. ;)

mailto:second_chance@cox.net
The Ultimate Guide To Modding: I-War 2 - Edge Of Chaos (on hold during SW MP mod)
cartoons.sev.com.au/index.php?catid=4
.

Please Log in or Create an account to join the conversation.