Class: Game_SelfVariables

Inherits:
Object show all
Defined in:
scripts/00600 Script_RMXP/03100 Game_SelfVariables.rb

Overview

Note:

This script should be after Interpreter 7

Hash gérant les variables locales. Des variables propres à l'évènement, Permet de ne pas devoir utiliser de variable de jeu pour gérer ce qui est propre à un évènement Dans les scrpit, la variable globale $game_self_variables contient les variables locales

Author:

  • Leikt

Instance Method Summary collapse

Constructor Details

#initializeGame_SelfVariables

Default initialization



13
14
15
# File 'scripts/00600 Script_RMXP/03100 Game_SelfVariables.rb', line 13

def initialize
  @data = {}
end

Instance Method Details

#[](key) ⇒ Object

Fetch the value of a self variable

Parameters:

  • key (Array)

    the key that identify the self variable

Returns:



19
20
21
# File 'scripts/00600 Script_RMXP/03100 Game_SelfVariables.rb', line 19

def [](key)
  return @data[key]
end

#[]=(key, value)

Set the value of a self variable

Parameters:

  • key (Array)

    the key that identify the self variable

  • value (Object)

    the new value



25
26
27
# File 'scripts/00600 Script_RMXP/03100 Game_SelfVariables.rb', line 25

def []=(key, value)
  @data[key] = value
end

#do(key, operation = nil, value = nil)

Perform an action on the specific variable and return the result

Parameters:

  • key (Array)

    the key that identify the self variable

  • operation (Symbol) (defaults to: nil)

    symbol of the operation to do on the variable

  • value (Object) (defaults to: nil)

    value associated to the operation



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'scripts/00600 Script_RMXP/03100 Game_SelfVariables.rb', line 32

def do(key, operation=nil, value=nil)
  @data[key]=0 unless @data.has_key?(key)
  case operation
  when :set
      @data[key]=value
  when :del
      @data.delete(key)

  # Numeric
  when :add
      @data[key]+=value
  when :sub
      @data[key]-=value
  when :div
      @data[key]/=value
  when :mul
      @data[key]*=value
  when :mod
      @data[key]=@data[key]%value
  when :count
      @data[key]+=1
  when :uncount
      @data[key]-=1

  # Boolean
  when :toggle
      @data[key]=!@data[key]
  when :and
      @data[key]=(@data[key] and value)
  when :or
      @data[key]=(@data[key] or value)
  when :xor
      @data[key]=(@data[key]^value)
  end
  # Return the data
  return @data[key]
end