Page 1 of 1

Faction:setInitialReaction versus Faction:setFactionReaction

Posted: Sat Jul 31, 2010 6:28 am
by yufra
I started implementing factions for my module, and had the following in my load.lua:

Code: Select all

-- Factions
Faction:add{ name="Infected", reaction={Players=-100, Staff=-100} }
Faction:add{ name="Staff", reaction={Players=0, Infected=-100} }
Faction:setFactionReaction("players", "infected", -100)
All of a sudden my player wasn't able to bump into and attack zombies (infected). A whole lot of debugging later and I fixed the problem by switching over to Faction:setInitialReaction. It appears that Faction:setFactionReaction stores the reaction in the actual game object (game.factions to be exact) which is checked before the actual Faction module itself. When this is used in load.lua the game.factions variable gets set to nil somewhere along the way and the reaction is lost. The Faction:setInitialReaction stores the reaction in the Faction module itself, which does not appear to be loaded multiple times and retains the reaction. Any thoughts as to where the game.factions variable is getting nilled, and what the intended differences between Faction:setInitialReaction and Faction:setFactionReaction are? Expanding the engine.Faction docstring and LuaDoc would be super, too. :)

Re: Faction:setInitialReaction versus Faction:setFactionReac

Posted: Sat Jul 31, 2010 10:09 am
by darkgod
It does not get nilled per say but load.lua is ran before "game" exists, since it's it that creates it at the very last line.
The game that exsits before that is the main game menu.

That's what the setInitialFactionReaction is for :)
setFactionReaction then stores changes in the savefile, think of it as a "diff" of factions

Re: Faction:setInitialReaction versus Faction:setFactionReac

Posted: Sat Jul 31, 2010 3:14 pm
by yufra
Ahhh, saved to the savefile that is what I am missing. I am attaching a patch that expands the documentation of engine.Faction functions. This may help other newbies. :)

Re: Faction:setInitialReaction versus Faction:setFactionReac

Posted: Sat Jul 31, 2010 3:21 pm
by yufra
Two small corrections to the above patch file, use this one instead.

Re: Faction:setInitialReaction versus Faction:setFactionReac

Posted: Sat Jul 31, 2010 3:29 pm
by darkgod
Thanks!