Faction:setInitialReaction versus Faction:setFactionReaction

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Faction:setInitialReaction versus Faction:setFactionReaction

#1 Post 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. :)
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Faction:setInitialReaction versus Faction:setFactionReac

#2 Post 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
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Faction:setInitialReaction versus Faction:setFactionReac

#3 Post 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. :)
Attachments
faction.diff.gz
(832 Bytes) Downloaded 144 times
<DarkGod> lets say it's intended

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Faction:setInitialReaction versus Faction:setFactionReac

#4 Post by yufra »

Two small corrections to the above patch file, use this one instead.
Attachments
faction.diff.gz
(850 Bytes) Downloaded 137 times
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Faction:setInitialReaction versus Faction:setFactionReac

#5 Post by darkgod »

Thanks!
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Post Reply