Arrays + Calls

Status
Not open for further replies.

Helladen

Deviant Designer
Veteran
Joined
Jul 13, 2012
Messages
635
Reaction score
188
First Language
English
I'm having trouble putting calls into a multi-dimensional array. Does anyone know a solution to turn a string to a call, or something else that could resolve this problem?
 
Last edited by a moderator:

Victor Sant

Veteran
Veteran
Joined
Mar 17, 2012
Messages
1,694
Reaction score
1,452
First Language
Portuguese
Primarily Uses
Just be careful with eval. It's a very consuming method and you should avoid by all means to place it on a method updated every frame.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I'm not sure what the question is.

Why do you want to evaluate a string as a method call?



Code:
def test
   p 'hello'
end

def another
   p 'another hello'
end

arr = [method(:another), method(:test)]
arr[0].call
arr[1].call

arr.each {|m| m.call}
 
Last edited by a moderator:

Helladen

Deviant Designer
Veteran
Joined
Jul 13, 2012
Messages
635
Reaction score
188
First Language
English
I guess I'll post it here. I have it designed out completely, but I ran into a problem. I plan on sharing it anyway, so it won't hurt anything.

It is not finished yet. I'm trying to get the scripts for variables working. I originally made it only to patch YEA - System Options which I had working, but I wanted to take it to the next level and allow all switches/variables to be used to call scripts. The options menu was going to do it for you automatically, but other things would require you to do an event script call. I can do all of that easy though.

# ▼ Switch and Variable Script Calls 1.0
# -- Last Updated: 2012.07.30
# -- Author: Helladen
#==============================================================================
# This will allow a developer to call specific things using switches and/or
# variables. This has support for YEA's System Options script.
#==============================================================================

#------------------------------------------------------------------------------
# ■ Aliased methods (YEA's System Options)
#------------------------------------------------------------------------------
# change_custom_variables
# change_custom_switch
#------------------------------------------------------------------------------

#==============================================================================
# ■ Instructions
#==============================================================================
# It will automatically call the script for you if you change them in
# YEA's System Options menu, but you will need to script call if it is not.
#
# You need to add each switch/variable you want and what it will call in the
# configuration below. Switches work differently than variables, they only call
# when they meet the requirements, where variables will always call and embed
# that value into the script call. For example, if you have a argument in your
# script call it will place the variable in the argument. This does not have
# support for multiple arguments, so you can't have a script call that has more
# than one.
#==============================================================================

#------------------------------------------------------------------------------
# ■ Event Script Calls
#------------------------------------------------------------------------------
# These are used to call the script for a variable or switch.
#
# call_switch_script(ID)
# call_variable_script(ID)
#
# ID is the given switch or variable index number.
#------------------------------------------------------------------------------

#==============================================================================
# ■ Configuration
#==============================================================================
module SCRIPT_CALLS
WINDOW_VARIABLE = 3

VARIABLES ={
# -------------------------------------------------------------------------
# index => call,
# -------------------------------------------------------------------------
3 => "$game_system.windowskin = Window",
}

#SWITCHES ={
# -------------------------------------------------------------------------
# index => [on/off, call],
# -------------------------------------------------------------------------
#1 => [true, ]
#}
end

#==============================================================================
# ■ Script Import
#==============================================================================
$imported = {} if $imported == nil
$imported["Switch and Variable Script Calls"] = true
#==============================================================================

# Compatibility for YEA's System Options
if $imported["YEA-SystemOptions"]
class Window_SystemOptions < Window_Command
#------------------------------------------------------------------------
# alias method: change_custom_variables
#------------------------------------------------------------------------
alias change_custom_variables_al change_custom_variables
def change_custom_variables(direction)
change_custom_variables_al(direction)
variable_script(SCRIPT_CALLS::WINDOW_VARIABLE)
end

#------------------------------------------------------------------------
# alias method: change_custom_switches
#------------------------------------------------------------------------
#alias change_custom_switch_al change_custom_switch
#def change_custom_switch(direction)
# change_custom_switch_al(direction)
#end

def variable_script(num)
#if $game_variables[SCRIPT_CALLS::WINDOW_VARIABLE] == 0
# $game_system.windowskin = "Window"
#else
# $game_system.windowskin = "Window" + $game_variables[SCRIPT_CALLS::WINDOW_VARIABLE].to_s
#end
eval(SCRIPT_CALLS::VARIABLES[num][0].to_s + $game_variables[num].to_s)
end
end
end

Code:
#==============================================================================
 
Last edited by a moderator:

Cidiomar

Veteran
Veteran
Joined
Apr 23, 2012
Messages
68
Reaction score
7
First Language
Portuguese
Primarily Uses
Code:
module SCRIPT_CALLS
WINDOW_VARIABLE = 3
end

module OptionsHelper
OptsIndex = {
3 => :set_windowskin
}
module_function
def set_windowskin(idx)
$game_system.windowskin = ('Window' + idx.to_s)
end
def callfunc(idx, *args)
send(OptsIndex[idx], *args)
end
end

$imported = {} unless $imported
$imported["Switch and Variable Script Calls"] = true
if $imported["YEA-SystemOptions"]
class Window_SystemOptions < Window_Command

alias change_custom_variables_al change_custom_variables
def change_custom_variables(direction)
change_custom_variables_al(direction)
variable_script(SCRIPT_CALLS::WINDOW_VARIABLE)
end

def variable_script(cmd_id, *args)
OptionsHelper.callfunc(cmd_id, *args)
end
end
end
You can do something like this.

And we need Ruby BBCode....
 

BigEd781

undefined method 'stupid_title' found for nil:NilC
Veteran
Joined
Mar 1, 2012
Messages
940
Reaction score
304
First Language
Dothraki
Primarily Uses
N/A
eval is evil and almost never necessary. Unless you are creating an interactive interpreter prefer function objects.
 

Helladen

Deviant Designer
Veteran
Joined
Jul 13, 2012
Messages
635
Reaction score
188
First Language
English
This is the fixed version.

Code:
#==============================================================================
# ▼ Switch and Variable Script Calls 1.0
# -- Last Updated: 2012.07.30
# -- Author: Helladen, Cidiomar
#==============================================================================
# This will allow a developer to call specific things using switches and/or
# variables. This requires YEA's System Options script. I may eventually add
# support for things outside of this, but at the moment I am not skilled enough
# to do so.
#==============================================================================

#------------------------------------------------------------------------------
# ■ Aliased methods (YEA's System Options)
#------------------------------------------------------------------------------
# change_custom_variables
# change_custom_switch
#------------------------------------------------------------------------------

#==============================================================================
# ■ Instructions
#==============================================================================
# You must specify an ID of a variable or switch you want to check for, this
# then allows you to call specific things after they have been changed in the
# System Options menu.
#==============================================================================

#==============================================================================
# ■ Installation
#==============================================================================
# Place below Yanfly Engine Ace - System Options.
#==============================================================================

#==============================================================================
# ■ Configuration
#==============================================================================
module OptionsHelper
VarOptsIndex = {
	3 => :set_windowskin
}

SwitchOptsIndex = {

}

module_function
def set_windowskin(idx)
	if $game_variables[idx] == 0
	 $game_system.windowskin = "Window"
	else
	 $game_system.windowskin = "Window" + $game_variables[idx].to_s
	end
end

def call_script(idx, type)
	if type
	 return unless SwitchOptsIndex[idx] != nil
	 send(SwitchOptsIndex[idx], idx)
	else
	 return unless VarOptsIndex[idx] != nil
	 send(VarOptsIndex[idx], idx)
	end
end
end

#==============================================================================

#==============================================================================
# ■ Script Import
#==============================================================================
$imported = {} if $imported == nil
$imported["Switch and Variable Script Calls"] = true
#==============================================================================

# Compatibility for YEA's System Options
if $imported["YEA-SystemOptions"]
	class Window_SystemOptions < Window_Command
	 #------------------------------------------------------------------------
	 # alias method: change_custom_variables
	 #------------------------------------------------------------------------
	 alias change_custom_variables_al change_custom_variables
	 def change_custom_variables(direction)
		change_custom_variables_al(direction)

		ext = current_ext
		var = YEA::SYSTEM::CUSTOM_VARIABLES[ext][0]

		# Call the variable's script.
		OptionsHelper::call_script(var, false)
	 end

	 #------------------------------------------------------------------------
	 # alias method: change_custom_switches
	 #------------------------------------------------------------------------
	 alias change_custom_switch_al change_custom_switch
	 def change_custom_switch(direction)
		change_custom_switch_al(direction)

		ext = current_ext
		switch = YEA::SYSTEM::CUSTOM_SWITCHES[ext][0]

		# Call the switch's script.
		OptionsHelper::call_script(switch, true)
	 end
	end
end
Does anyone know of a way to check variables/switches changing? If not do I need to make my own function to do this?
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Look at Game_Switches and Game_Variables classes and how they are setting the values.

It is already telling the map to refresh, so you just need to add to it.
 

Celianna

Tileset artist
Veteran
Joined
Mar 1, 2012
Messages
10,557
Reaction score
5,592
First Language
Dutch
Primarily Uses
RMMV
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,072
Members
137,578
Latest member
JamesLightning
Top