Module: TyranoDsl::ParsingWords::ConditionalJump

Includes:
ParsingWordsModule
Defined in:
lib/tyrano_dsl/parsing_words/conditional_jump.rb

Constant Summary collapse

VALID_OPERATORS =
[
    '<',
    '>',
    '==',
    '!=',
]

Instance Method Summary collapse

Instance Method Details

#conditional_jump(variable, operator, value, scene_name, label_name = nil) ⇒ void

This method returns an undefined value.

Parameters:

  • variable (String)
  • operator (String)
  • value (String, Symbol, Float)
  • scene_name (String)
  • label_name (String, nil) (defaults to: nil)

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tyrano_dsl/parsing_words/conditional_jump.rb', line 23

def conditional_jump(variable, operator, value, scene_name, label_name = nil)
  check_variable_exist(variable)
  if value.is_a?(String) || value.is_a?(Symbol)
    check_variable_exist(value)
  end
  unless VALID_OPERATORS.include? operator
    raise TyranoDsl::TyranoException, "Unknown operator [#{operator}]"
  end
  add_parsed_word(
      TyranoDsl::Vocabulary::CONDITIONAL_JUMP,
      variable: variable,
      operator: operator,
      value: value,
      scene_name: scene_name,
      label_name: label_name
  )
  label = label_name ? context.world.label_value(label_name) : nil
  context.world.jump_targets << TyranoDsl::Elements::JumpTarget.new(scene_name, label)
end