PDA

View Full Version : Invisible Placeables instead of Globals...


Agent Xim
09-20-2006, 07:12 PM
In one of the Korriban mods I'm working on (Dreshdae Underground) I was trying to figure out which Globals to use in the Arena. When my eyes crossed... I instead decided to spawn invisible placeables (with unique tags) after certain conditions, then simply check using IsObjectValid to move the plot along (plus the placeables stay spawned until destroyed even when exiting and returning to the area).

This method, of course, is only useful for area-specific checks (once you leave the area, access to those objects is gone and thus any check would always fail) however, there's no chance of overwriting globals used by other modders or even the game itself. Seems to work well enough for my needs!

I hope the above is clear enough ;)

So, my questions:

Does anyone else use this method?
Would it be "safer" to use a real Global?

Thanks!
Xim

tk102
09-20-2006, 07:17 PM
I like it! :thumbsup: Never used it before, but I can't see any reason it wouldn't be just as safe as a global. Of course the advantage/disadvantage it has is that is area-specific. I think I remember coming across a script that checked for the existance of a waypoint in an IF statement and the spawned the waypoint if it didn't exist. You could use those as well and call GetWaypointByTag. That way you wouldn't even need a .utp...

vvv-- of course stoffe will have something more informative to say about this. :xp:

stoffe
09-20-2006, 07:34 PM
This method, of course, is only useful for area-specific checks (once you leave the area, access to those objects is gone and thus any check would always fail) however, there's no chance of overwriting globals used by other modders or even the game itself.

Should work. There is little point in using global variables to begin with if you only need to access the values from within a single area, unless you need the other data types that local variables don't provide.

However, for custom areas I'd just use local variables set on the area to keep track of things instead of spawning multiple placeables. Like:

void main() {
object oArea = GetArea(OBJECT_SELF);
SetLocalBoolean(oArea, 10, TRUE);
SetLocalNumber(oArea, 2, 12);
// ...
if (GetLocalBoolean(oArea, 10)) {
SendMessageToPC(GetPartyLeader(), "The number is " + IntToString(GetLocalNumber(oArea, 2)));
}
}


This way you won't need to spawn extra objects. Or, if this is for one of the standard game areas and you want to avoid LocalNum/bool conflicts with other mods you can spawn a single invisible placeable with a unique tag and set all your Locals on that placeable. Then you'd have the full range of LocalBooleans and LocalNumbers at your disposal without any conflicts. Like:

void main() {
object oVars = GetObjectByTag("ST_PLC_MyVariables");
if (!GetIsObjectValid(oVars)) {
oVars = CreateObject(OBJECT_TYPE_PLACEABLE, "st_myvars1", Location([0.0,0.0,0.0], 0.0));
}

SetLocalBoolean(oVars, 10, TRUE);
SetLocalNumber(oVars, 2, 12);
// ...
if (GetLocalBoolean(oVars, 10)) {
SendMessageToPC(GetPartyLeader(), "The number is " + IntToString(GetLocalNumber(oVars, 2)));
}
}


It's less work for the game to keep track of local variables than it is to keep track of multiple object instances for placeables. Not that that would really matter unless you do something very complex, I doubt anything bad would happen if the memory requirement and savegame size grew with a 100Kb or so from the extra placeable info to keep track of... :)

Agent Xim
09-20-2006, 07:37 PM
:clap2: Thanks TK, especially for GetWaypointByTag... I'll just use that in the future!

Edit: Wow, thanks for the info stoffe. I didn't realize that was even possible lol.

Edit 2: stoffe, you are brilliant! That will come in handy for another mod I was struggling with :)