Top Level Namespace

Instance Method Summary (collapse)

Instance Method Details

- (Hash) match_get(pattern)

Matches regex patterns and returns pattern name along with matched text

Examples:

Retrieve the text from a matching pattern.

put "open my trunk"
match = { :m => [/you open/i] }
result = match_get match
result #=> {:key =>:m, :match => "You open the steel trunk..."}

Parameters:

  • pattern (Hash)

    list of regex patterns and names

Returns:

  • (Hash)

    name and text from the matching pattern



70
71
72
73
74
75
76
77
78
# File 'text.rb', line 70

def match_get(pattern)
  validate_pattern pattern

  $_api_exec_state = :match_get

  match = api_get_match pattern, Hash[pattern.keys.collect{ |v| [v, ""] }]
  m = match.find{ |k, v| !v.empty? }
  {:key => m[0], :match => m[1]}
end

- (Hash) match_get_m(pattern)

Match get for multiple lines.

Examples:

Retrieve text from matching patterns.

put "health"
match = {:vitals => [/Your/],
         :scars => [/You have/],
         :match_end => [/>|\.\.\.wait|you may only type ahead/]}
result = match_get_m match
result #=>
#{:vitals=>["Your body feels very beat up.", "Your spirit feels full of life."],
# :scars=>["You have some tiny scratches to the neck."],
# :match_end=>[">"]}

Parameters:

  • pattern (Hash)

    list of regex patterns and names

Returns:

  • (Hash)

    found matches arranged by pattern names



94
95
96
97
98
99
100
101
# File 'text.rb', line 94

def match_get_m(pattern)
  validate_get_m validate_pattern pattern

  $_api_exec_state = :match_get_m

  match = api_get_match pattern, Hash[pattern.keys.collect{ |v| [v, []] }]
  match.delete_if{ |k, v| v.empty? }
end

- (Symbol) match_wait(pattern)

Matches regex patterns and returns the name of the matching pattern.

Examples:

Match for game text.

match = { :retry => [/\.\.\.wait/], :open => [/you open/] }
result = match_wait match
result #=> :retry or :open
case result
  when :open
    echo "open!"
end

Parameters:

  • pattern (Hash)

    list of regex patterns and names

Returns:

  • (Symbol)

    name of the regex pattern



53
54
55
56
57
58
59
# File 'text.rb', line 53

def match_wait(pattern)
  validate_pattern pattern
  $_api_exec_state = :match_wait

  match = api_get_match pattern, Hash[pattern.keys.collect{ |v| [v, ""] }]
  match.find{ |k, v| !v.empty? }.first
end

- (Void) match_wait_goto(pattern)

Matches regex patterns and calls the defined label.

Examples:

Using match patterns and jumping to labels on a successful match.

labels_start

label(:retry){
  match = { :retry => [/\.\.\.wait/], :next => [/you open/] }
  match_wait_goto match
}

label(:next){
  echo "next"
}

labels_end

Parameters:

  • pattern (Hash)

    list of regex patterns and names

Returns:

  • (Void)


120
121
122
123
124
125
# File 'text.rb', line 120

def match_wait_goto(pattern)
  $_api_exec_state = :match_wait_goto

  match = api_get_match pattern, Hash[pattern.keys.collect{ |v| [v, ""] }]
  goto match.find{ |k, v| !v.empty? }.first
end

- (void) wait

This method returns an undefined value.

Waits for a prompt character.

Examples:

Using wait in script to run consecutive commands.

put "remove my shield"
wait
put "wear my shield"
wait
put "remove my shield"


136
137
138
139
# File 'text.rb', line 136

def wait
  #$_api_queue.clear
  wait_for(/>/)
end

- (void) wait_for(pattern)

This method returns an undefined value.

Runs until matching regex pattern is found in game text.

Parameters:

  • pattern (String)

    regex pattern.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'text.rb', line 25

def wait_for(pattern)
  $_api_exec_state = :wait_for
  if pattern.is_a?(Array)
    pattern = Regexp.new(pattern.join('|'))
  end

  (0..1000000).each do
    line = API::sync_read
    if line and line.match(pattern)
        $_api_exec_state = :none
        return
    end
    sleep 0.01
  end
end

- (void) wait_for_roundtime

This method returns an undefined value.

Waits for roundtime and pauses for the duration.

Examples:

Wait for the duration of round time before executing next command.

put "hide"
wait_for_roundtime
put "unhide"


8
9
10
11
12
13
14
15
16
17
18
19
# File 'text.rb', line 8

def wait_for_roundtime
  $_api_exec_state = :wait_for_roundtime
  (0..1000000).each do
    line = API::sync_read
    if line and line.match(/Roundtime/)
        $_api_exec_state = :none
        API::sleep_rt line[/\d+/].to_i + $rt_adjust
        return
    end
    sleep 0.01
  end
end