Class: TyranoDsl::WritingWords::UpdateVariable

Inherits:
Object
  • Object
show all
Includes:
WritingWordsModule
Defined in:
lib/tyrano_dsl/writing_words/update_variable.rb

Instance Method Summary collapse

Methods included from WritingWordsModule

#fetch_scene, #h, #raise_unknown

Instance Method Details

#run(writing_context, world, word_location, parameters) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tyrano_dsl/writing_words/update_variable.rb', line 7

def run(writing_context, world, word_location, parameters)
  operator = parameters[:operator]
  variable = parameters[:variable]
  value = parameters[:value]
  variable_target = world.variables[variable].target_name
  if value.is_a?(String) || value.is_a?(Symbol)
    val = world.variables[value].target_name
    value_target = "f.#{val}"
    op = 'h'
  else
    val = value
    value_target = value
    op = 't'
  end

  writing_context.append_content(
      word_location,
      "[tb_eval  exp=\"f.#{variable_target}#{operator}#{value_target}\"  name=\"#{variable_target}\"  cmd=\"#{operator}\"  op=\"#{op}\"  val=\"#{val}\"  val_2=\"undefined\"]"
  )
end