Page 1 of 1
Whats the first thing called by a loading game?
Posted: 03 Apr 2012, 20:16
by Erik
I would want to ensure creating a game variable (same value for everyone but random per game session) before gadgets and unitdefs(post) load so i can use it there and rely on it being initialized already.
If possible i would even have loading screens based on that value.
Any suggestions?
Re: Whats the first thing called by a loading game?
Posted: 06 Apr 2012, 10:33
by knorke
not sure what you mean..
in function gadget:GetInfo() you have the layer= <some number> thing, which defines order in which wupgets are loaded.
So you can one have load first, then the others all after that one.
a game variable (same value for everyone but random per game session)
Game.gameID
http://springrts.com/wiki/Lua_ConstGame
If possible i would even have loading screens based on that value.
Not possible, loadscreens are chosen by engine atm.
Re: Whats the first thing called by a loading game?
Posted: 06 Apr 2012, 14:45
by FLOZi
which defines order in which wupgets are EXECUTED.
Fixed.
Also the Game table isn't accessible at defs loading stage
Re: Whats the first thing called by a loading game?
Posted: 06 Apr 2012, 14:57
by knorke
Also the Game table isn't accessible at defs loading stage
yea,
i just remebered...
Well, what do you want to do? There might be another way.
Re: Whats the first thing called by a loading game?
Posted: 06 Apr 2012, 21:27
by Erik
I want to have a random (but same for everyone, also in replays) variable(like a special game mode) and based on that change stuff like
-unit stats(this game all tank have double HP, or now you can also build experimental unit xyz which is added to this units build list)
-enable certain gadgets(i.e. alternative victory condition)
-change the spawned units at game start.(like start with not only a headquarter but also some tanks this time)
ideally I would like to show the currently active "special feature/game mode" while the game loads or in a popup window at game start (like zk does for commander selection)
Re: Whats the first thing called by a loading game?
Posted: 07 Apr 2012, 02:46
by knorke
math.random() will do fine in synced part. (not sure if it needs to be seeded somehow)
hm.
it comes down to two things:
1) stuff you can do with normal gadgets:
eg en/disableing certain gadgets or spawning different startunits.
To some extend you can change attributes of units, eg there is Spring.SetUnitMaxHealth (needs some scripting since it is per unitID, but nothing impossible hard) so some things do not _post.
2) stuff you can only do in bla_post.lua:
eg changing the movement class of a unit.
I think there is no way to pass stuff from unitdef_post to ingame lua, except for the unitdefs themselves.
But imo forget about doing much dynamic stuff in _post and use gadgets for everything.
For the things listed you do not need _post, though editing buildlist is a bit tricky. (can not really edit the buildlist but only hide the buttons and block the unit creation)
Re: Whats the first thing called by a loading game?
Posted: 07 Apr 2012, 03:17
by Beherith
Isnt this what the layer tag is for in the gadget.getinfo?
Re: Whats the first thing called by a loading game?
Posted: 07 Apr 2012, 12:15
by FLOZi
except for the unitdefs themselves.
This is precisely how to do it. Stick a value in a junk unitdef during loading and it will be accessible everywhere.
Beherith: Layer controls execution order, not loading order.
Re: Whats the first thing called by a loading game?
Posted: 09 Apr 2012, 07:53
by CarRepairer
Erik wrote:I want to have a random (but same for everyone, also in replays) variable(like a special game mode) and based on that change stuff like
-unit stats(this game all tank have double HP, or now you can also build experimental unit xyz which is added to this units build list)
-enable certain gadgets(i.e. alternative victory condition)
-change the spawned units at game start.(like start with not only a headquarter but also some tanks this time)
ideally I would like to show the currently active "special feature/game mode" while the game loads or in a popup window at game start (like zk does for commander selection)
1) Randomize the unit stats in unitdefspost.
2) Make a central gadget with low layer that controls victory conditions. Use setgamrulesparam in it and other gadgets will function by checking getgamerulesparam.
3) This gadet will also check unitdefs to see what happened in step 1.
4) It can spawn start units as you please.
5) Make a widget that reads getgamerulesparam and displays a window of information.
Re: Whats the first thing called by a loading game?
Posted: 09 Apr 2012, 11:25
by Erik
Everything (excluding unitdefs post) working.