[Gamefic] Using .session to store values?

Wohoo, the first proper authoring gamefic question!

In the master-tape code, I see the use of .session to store values. Is that a pattern you recommend?

For example - returning to that cracked mirror example - is this a good way of doing it?


mirror = make Item,
	:name => 'mirror',
	:parent => gallery,
	:description => "A mirror"

mirror.session[:cracked]=false

respond :look, Query.new(:siblings, mirror) do |actor, mirror|
  actor.tell "The mirror is #{mirror.session[:cracked] ? 'cracked' : 'intact'}."
  unless mirror.session[:cracked] then
  	actor.tell "Uh oh. You dropped it."
  	mirror.session[:cracked] = true
  end
end

Or is it better to create classes or mix-ins to store values in actual instance fields? Is there anything particular I should think of regarding this?

:stuck_out_tongue:

Yeah, that’s the type of thing I intended for it. Pretty much any kind of simple variable that didn’t warrant extending the class. It might be worthwhile to add some syntactic sugar for it to the Entity class, so you could access it like mirror[:cracked], but I figure it’s a useful mechanism for quick prototyping, if nothing else.

It’s worth noting that the WIP I have for saving and restoring the game states keeps the session data, so practically anything that can be serialized (including entities) should be safe in there across reloads.