Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
zahraa

2 easy script request (solved by diagostimo)

Recommended Posts

1.

when you have at least one savefile and choose new game,i want that a window comes and ask "are you sure?".please edit this script:(this is RMXP default title script)

 

 

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

# ** Scene_Title

#------------------------------------------------------------------------------

# This class performs title screen processing.

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

class Scene_Title

#--------------------------------------------------------------------------

# * Main Processing

#--------------------------------------------------------------------------

def main

# If battle test

if $BTEST

battle_test

return

end

# Load database

$data_actors = load_data("Data/Actors.rxdata")

$data_classes = load_data("Data/Classes.rxdata")

$data_skills = load_data("Data/Skills.rxdata")

$data_items = load_data("Data/Items.rxdata")

$data_weapons = load_data("Data/Weapons.rxdata")

$data_armors = load_data("Data/Armors.rxdata")

$data_enemies = load_data("Data/Enemies.rxdata")

$data_troops = load_data("Data/Troops.rxdata")

$data_states = load_data("Data/States.rxdata")

$data_animations = load_data("Data/Animations.rxdata")

$data_tilesets = load_data("Data/Tilesets.rxdata")

$data_common_events = load_data("Data/CommonEvents.rxdata")

$data_system = load_data("Data/System.rxdata")

# Make system object

$game_system = Game_System.new

# Make title graphic

@sprite = Sprite.new

@sprite.bitmap = RPG::Cache.title($data_system.title_name)

# Make command window

s1 = "New Adventure"

s2 = "Continue Way"

s3 = "Exit"

@command_window = Window_Command.new(192, [s1, s2, s3])

@command_window.back_opacity = 160

@command_window.x = 320 - @command_window.width / 2

@command_window.y = 288

# Continue enabled determinant

# Check if at least one save file exists

# If enabled, make @continue_enabled true; if disabled, make it false

@continue_enabled = false

for i in 0..3

if FileTest.exist?("Save#{i+1}.rxdata")

@continue_enabled = true

end

end

# If continue is enabled, move cursor to "Continue"

# If disabled, display "Continue" text in gray

if @continue_enabled

@command_window.index = 1

else

@command_window.disable_item(1)

end

# Play title BGM

$game_system.bgm_play($data_system.title_bgm)

# Stop playing ME and BGS

Audio.me_stop

Audio.bgs_stop

# Execute transition

Graphics.transition

# Main loop

loop do

# Update game screen

Graphics.update

# Update input information

Input.update

# Frame update

update

# Abort loop if screen is changed

if $scene != self

break

end

end

# Prepare for transition

Graphics.freeze

# Dispose of command window

@command_window.dispose

# Dispose of title graphic

@sprite.bitmap.dispose

@sprite.dispose

end

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

def update

# Update command window

@command_window.update

# If C button was pressed

if Input.trigger?(Input::C)

# Branch by command window cursor position

case @command_window.index

when 0 # New game

command_new_game

when 1 # Continue Way

command_continue

when 2 # Shutdown

command_shutdown

end

end

end

#--------------------------------------------------------------------------

# * Command: New Game

#--------------------------------------------------------------------------

def command_new_game

 

# Play decision SE

$game_system.se_play($data_system.decision_se)

# Stop BGM

Audio.bgm_stop

# Reset frame count for measuring play time

Graphics.frame_count = 0

# Make each type of game object

$game_temp = Game_Temp.new

$game_system = Game_System.new

$game_switches = Game_Switches.new

$game_variables = Game_Variables.new

$game_self_switches = Game_SelfSwitches.new

$game_screen = Game_Screen.new

$game_actors = Game_Actors.new

$game_party = Game_Party.new

$game_troop = Game_Troop.new

$game_map = Game_Map.new

$game_player = Game_Player.new

# Set up initial party

$game_party.setup_starting_members

# Set up initial map position

$game_map.setup($data_system.start_map_id)

# Move player to initial position

$game_player.moveto($data_system.start_x, $data_system.start_y)

# Refresh player

$game_player.refresh

# Run automatic change for BGM and BGS set with map

$game_map.autoplay

# Update map (run parallel process event)

$game_map.update

# Switch to map screen

$scene = Scene_Map.new

end

end

#--------------------------------------------------------------------------

# * Command: Continue

#--------------------------------------------------------------------------

def command_continue

# If continue is disabled

unless @continue_enabled

# Play buzzer SE

$game_system.se_play($data_system.buzzer_se)

return

end

# Play decision SE

$game_system.se_play($data_system.decision_se)

# Switch to load screen

$scene = Scene_Load.new

end

#--------------------------------------------------------------------------

# * Command: Shutdown

#--------------------------------------------------------------------------

def command_shutdown

# Play decision SE

$game_system.se_play($data_system.decision_se)

# Fade out BGM, BGS, and ME

Audio.bgm_fade(800)

Audio.bgs_fade(800)

Audio.me_fade(800)

# Shutdown

$scene = nil

end

#--------------------------------------------------------------------------

# * Battle Test

#--------------------------------------------------------------------------

def battle_test

# Load database (for battle test)

$data_actors = load_data("Data/BT_Actors.rxdata")

$data_classes = load_data("Data/BT_Classes.rxdata")

$data_skills = load_data("Data/BT_Skills.rxdata")

$data_items = load_data("Data/BT_Items.rxdata")

$data_weapons = load_data("Data/BT_Weapons.rxdata")

$data_armors = load_data("Data/BT_Armors.rxdata")

$data_enemies = load_data("Data/BT_Enemies.rxdata")

$data_troops = load_data("Data/BT_Troops.rxdata")

$data_states = load_data("Data/BT_States.rxdata")

$data_animations = load_data("Data/BT_Animations.rxdata")

$data_tilesets = load_data("Data/BT_Tilesets.rxdata")

$data_common_events = load_data("Data/BT_CommonEvents.rxdata")

$data_system = load_data("Data/BT_System.rxdata")

# Reset frame count for measuring play time

Graphics.frame_count = 0

# Make each game object

$game_temp = Game_Temp.new

$game_system = Game_System.new

$game_switches = Game_Switches.new

$game_variables = Game_Variables.new

$game_self_switches = Game_SelfSwitches.new

$game_screen = Game_Screen.new

$game_actors = Game_Actors.new

$game_party = Game_Party.new

$game_troop = Game_Troop.new

$game_map = Game_Map.new

$game_player = Game_Player.new

# Set up party for battle test

$game_party.setup_battle_test_members

# Set troop ID, can escape flag, and battleback

$game_temp.battle_troop_id = $data_system.test_troop_id

$game_temp.battle_can_escape = true

$game_map.battleback_name = $data_system.battleback_name

# Play battle start SE

$game_system.se_play($data_system.battle_start_se)

# Play battle BGM

$game_system.bgm_play($game_system.battle_bgm)

# Switch to battle screen

$scene = Scene_Battle.new

end

 

 

 

2.

and the same thing for shutdown when you are playing the game.a window comes and ask "are you sure ?" please edit this script:(this is RMXP default end script)

 

 

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

# ** Scene_End

#------------------------------------------------------------------------------

# This class performs game end screen processing.

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

class Scene_End

#--------------------------------------------------------------------------

# * Main Processing

#--------------------------------------------------------------------------

def main

# Make command window

s1 = "To Title"

s2 = "Leave Quest"

s3 = "Cancel"

@command_window = Window_Command.new(192, [s1, s2, s3])

@command_window.x = 320 - @command_window.width / 2

@command_window.y = 240 - @command_window.height / 2

# Execute transition

Graphics.transition

# Main loop

loop do

# Update game screen

Graphics.update

# Update input information

Input.update

# Frame Update

update

# Abort loop if screen is changed

if $scene != self

break

end

end

# Prepare for transition

Graphics.freeze

# Dispose of window

@command_window.dispose

# If switching to title screen

if $scene.is_a?(Scene_Title)

# Fade out screen

Graphics.transition

Graphics.freeze

end

end

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

def update

# Update command window

@command_window.update

# If B button was pressed

if Input.trigger?(Input::B)

# Play cancel SE

$game_system.se_play($data_system.cancel_se)

# Switch to menu screen

$scene = Scene_Menu.new(5)

return

end

# If C button was pressed

if Input.trigger?(Input::C)

# Branch by command window cursor position

case @command_window.index

when 0 # to title

command_to_title

when 1 # shutdown

command_shutdown

when 2 # quit

command_cancel

end

return

end

end

#--------------------------------------------------------------------------

# * Process When Choosing [To Title] Command

#--------------------------------------------------------------------------

def command_to_title

# Play decision SE

$game_system.se_play($data_system.decision_se)

# Fade out BGM, BGS, and ME

Audio.bgm_fade(800)

Audio.bgs_fade(800)

Audio.me_fade(800)

# Switch to title screen

$scene = Scene_Title.new

end

#--------------------------------------------------------------------------

# * Process When Choosing [shutdown] Command

#--------------------------------------------------------------------------

def command_shutdown

# Play decision SE

$game_system.se_play($data_system.decision_se)

# Fade out BGM, BGS, and ME

Audio.bgm_fade(800)

Audio.bgs_fade(800)

Audio.me_fade(800)

# Shutdown

$scene = nil

end

#--------------------------------------------------------------------------

# * Process When Choosing [Cancel] Command

#--------------------------------------------------------------------------

def command_cancel

# Play decision SE

$game_system.se_play($data_system.decision_se)

# Switch to menu screen

$scene = Scene_Menu.new(5)

end

end

 

 

 

please answer.i think it takes 5 min for scripters

thanks

Edited by zahraa

Share this post


Link to post
Share on other sites

First you'll need this Window_Dialog script I just wrote:

 

 

class Window_Dialog < Window_Base
def initialize(prompt, rtrn_var, w_width = 480)
	w_height = mk_lns(prompt, w_width).length * 32 + 32
	super((640 - w_width) / 2, (480 - w_height) / 2, w_width, w_height)
	self.contents = Bitmap.new(width - 32, height - 32)
	@prompt = mk_lns(prompt, width)
	@rtrn_var = rtrn_var
	@choice = 0

	loop do
		Graphics.update
		Input.update
		update
		break unless self
	end
end

def update
	@choice = @choice == 1 ? 0 : 1 if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
	set_cursor_rect(@choice * (width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32)
	if Input.trigger?(Input::C)
		eval("#{@rtrn_var}=" + (@choice == 1).to_s)
		$game_system.se_play($data_system.decision_se) if @choice == 1
		$game_system.se_play($data_system.cancel_se) if @choice == 0
		dispose
	end
	refresh
end

def refresh
	for i in 0...@prompt.length
		t_width = self.contents.text_size(@prompt[i])[0]
		self.contents.draw_text(Rect.new(0, i * 32, t_width, 32), @prompt[i])
	end
	self.contents.draw_text(Rect.new(0, @prompt.length * 32 + 8, (width - 32) / 2, 32), "Yes", 1)
	self.contents.draw_text(Rect.new((width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32), "No", 1)
end

def mk_lns(txt, txt_width)
	lns = []
	text_array = txt.split(/ /)
	ln = ""
	while text_array != []
		ln += text_array.shift
		if self.contents.text_size(ln)[0] > txt_width - 32
			if ln.split(/ /).length == 1
				tmp = ""
				while self.contents.text_size(ln)[0] > txt_width - 32
					tmp += ln[0..0]
					ln[0..0] = ""
				end
				text_array.unshift(tmp)
			else
				ln = ln.split(/ /)
				ln.pop
				ln = ln.join(" ")
			end
			lns.push(ln)
			ln = ""
		end
	end
	return lns
end
end

 

 

 

And here's the edited Scene_Title.

 

 

#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# If battle test
if $BTEST
battle_test
return
end
# Load database
$data_actors = load_data("Data/Actors.rxdata")
$data_classes = load_data("Data/Classes.rxdata")
$data_skills = load_data("Data/Skills.rxdata")
$data_items = load_data("Data/Items.rxdata")
$data_weapons = load_data("Data/Weapons.rxdata")
$data_armors = load_data("Data/Armors.rxdata")
$data_enemies = load_data("Data/Enemies.rxdata")
$data_troops = load_data("Data/Troops.rxdata")
$data_states = load_data("Data/States.rxdata")
$data_animations = load_data("Data/Animations.rxdata")
$data_tilesets = load_data("Data/Tilesets.rxdata")
$data_common_events = load_data("Data/CommonEvents.rxdata")
$data_system = load_data("Data/System.rxdata")
# Make system object
$game_system = Game_System.new
# Make title graphic
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
# Make command window
s1 = "New Adventure"
s2 = "Continue Way"
s3 = "Exit"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.back_opacity = 160
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 288
# Continue enabled determinant
# Check if at least one save file exists
# If enabled, make @continue_enabled true; if disabled, make it false
@continue_enabled = false
for i in 0..3
if FileTest.exist?("Save#{i+1}.rxdata")
@continue_enabled = true
end
end
# If continue is enabled, move cursor to "Continue"
# If disabled, display "Continue" text in gray
if @continue_enabled
@command_window.index = 1
else
@command_window.disable_item(1)
end
# Play title BGM
$game_system.bgm_play($data_system.title_bgm)
# Stop playing ME and BGS
Audio.me_stop
Audio.bgs_stop
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of command window
@command_window.dispose
# Dispose of title graphic
@sprite.bitmap.dispose
@sprite.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update command window
@command_window.update
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 0 # New game
command_new_game
when 1 # Continue Way
command_continue
when 2 # Shutdown
command_shutdown
end
end
end
#--------------------------------------------------------------------------
# * Command: New Game
#--------------------------------------------------------------------------
def command_new_game

# Play decision SE
$game_system.se_play($data_system.decision_se)

Window_Dialog.new("Are you sure?", "answer", 320)

if answer
# Stop BGM
Audio.bgm_stop
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each type of game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# Set up initial party
$game_party.setup_starting_members
# Set up initial map position
$game_map.setup($data_system.start_map_id)
# Move player to initial position
$game_player.moveto($data_system.start_x, $data_system.start_y)
# Refresh player
$game_player.refresh
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
end
end
#--------------------------------------------------------------------------
# * Command: Continue
#--------------------------------------------------------------------------
def command_continue
# If continue is disabled
unless @continue_enabled
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to load screen
$scene = Scene_Load.new
end
#--------------------------------------------------------------------------
# * Command: Shutdown
#--------------------------------------------------------------------------
def command_shutdown
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Fade out BGM, BGS, and ME
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Shutdown
$scene = nil
end
#--------------------------------------------------------------------------
# * Battle Test
#--------------------------------------------------------------------------
def battle_test
# Load database (for battle test)
$data_actors = load_data("Data/BT_Actors.rxdata")
$data_classes = load_data("Data/BT_Classes.rxdata")
$data_skills = load_data("Data/BT_Skills.rxdata")
$data_items = load_data("Data/BT_Items.rxdata")
$data_weapons = load_data("Data/BT_Weapons.rxdata")
$data_armors = load_data("Data/BT_Armors.rxdata")
$data_enemies = load_data("Data/BT_Enemies.rxdata")
$data_troops = load_data("Data/BT_Troops.rxdata")
$data_states = load_data("Data/BT_States.rxdata")
$data_animations = load_data("Data/BT_Animations.rxdata")
$data_tilesets = load_data("Data/BT_Tilesets.rxdata")
$data_common_events = load_data("Data/BT_CommonEvents.rxdata")
$data_system = load_data("Data/BT_System.rxdata")
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# Set up party for battle test
$game_party.setup_battle_test_members
# Set troop ID, can escape flag, and battleback
$game_temp.battle_troop_id = $data_system.test_troop_id
$game_temp.battle_can_escape = true
$game_map.battleback_name = $data_system.battleback_name
# Play battle start SE
$game_system.se_play($data_system.battle_start_se)
# Play battle BGM
$game_system.bgm_play($game_system.battle_bgm)
# Switch to battle screen
$scene = Scene_Battle.new
end

 

 

And finally Scene_End.

 

 

#==============================================================================
# ** Scene_End
#------------------------------------------------------------------------------
# This class performs game end screen processing.
#==============================================================================
class Scene_End
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
s1 = "To Title"
s2 = "Leave Quest"
s3 = "Cancel"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 240 - @command_window.height / 2
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame Update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of window
@command_window.dispose
# If switching to title screen
if $scene.is_a?(Scene_Title)
# Fade out screen
Graphics.transition
Graphics.freeze
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update command window
@command_window.update
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(5)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 0 # to title
command_to_title
when 1 # shutdown
command_shutdown
when 2 # quit
command_cancel
end
return
end
end
#--------------------------------------------------------------------------
# * Process When Choosing [To Title] Command
#--------------------------------------------------------------------------
def command_to_title
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Fade out BGM, BGS, and ME
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Switch to title screen
$scene = Scene_Title.new
end
#--------------------------------------------------------------------------
# * Process When Choosing [shutdown] Command
#--------------------------------------------------------------------------
def command_shutdown

Window_Dialog.new("Are you sure?", "answer", 320)

if answer
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Fade out BGM, BGS, and ME
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Shutdown
$scene = nil
end
end
#--------------------------------------------------------------------------
# * Process When Choosing [Cancel] Command
#--------------------------------------------------------------------------
def command_cancel
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to menu screen
$scene = Scene_Menu.new(5)
end
end

 

 

That should work, but if you get any errors, post pictures so I can see what's going on (I don't have RMXP anymore).

Share this post


Link to post
Share on other sites

Sorry about that, I forgot to check if the window still existed in the update method. This should work: I checked through for other bugs.

 

 

class Window_Dialog < Window_Base
def initialize(prompt, rtrn_var, w_width = 480)
	w_height = mk_lns(prompt, w_width).length * 32 + 32
	super((640 - w_width) / 2, (480 - w_height) / 2, w_width, w_height)
	self.contents = Bitmap.new(width - 32, height - 32)
	@prompt = mk_lns(prompt, width)
	@rtrn_var = rtrn_var
	@choice = 0

	loop do
		Graphics.update
		Input.update
		update
		break unless self
	end
end

def update
	break unless self
	@choice = @choice == 1 ? 0 : 1 if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
    self.cursor_rect.set(@choice * (width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32)
	if Input.trigger?(Input::C)
		eval("#{@rtrn_var}=" + (@choice == 1).to_s)
		$game_system.se_play($data_system.decision_se) if @choice == 1
		$game_system.se_play($data_system.cancel_se) if @choice == 0
		dispose
	end
	refresh
end

def refresh
	for i in 0...@prompt.length
		t_width = self.contents.text_size(@prompt[i])[0]
		self.contents.draw_text(Rect.new(0, i * 32, t_width, 32), @prompt[i])
	end
	self.contents.draw_text(Rect.new(0, @prompt.length * 32 + 8, (width - 32) / 2, 32), "Yes", 1)
	self.contents.draw_text(Rect.new((width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32), "No", 1)
end

def mk_lns(txt, txt_width)
	lns = []
	text_array = txt.split(/ /)
	ln = ""
	while text_array != []
		ln += text_array.shift
		if self.contents.text_size(ln)[0] > txt_width - 32
			if ln.split(/ /).length == 1
				tmp = ""
				while self.contents.text_size(ln)[0] > txt_width - 32
					tmp += ln[0..0]
					ln[0..0] = ""
				end
				text_array.unshift(tmp)
			else
				ln = ln.split(/ /)
				ln.pop
				ln = ln.join(" ")
			end
			lns.push(ln)
			ln = ""
		end
	end
	return lns
end
end

 

Edited by Thallion

Share this post


Link to post
Share on other sites

i copied this script in a new page and replaced "edited Scene_End" instead of default Scene_End and run my game.but when i go to menu and choose end and next shutdown,that error comes again.ermm.gif

even when i start a new project and do same things,this error comes

Share this post


Link to post
Share on other sites

Edit. I fixed it. Now I'm sure it'll work.

 

 

class Window_Dialog < Window_Base
   def initialize(prompt, rtrn_var, w_width = 480)
       w_height = mk_lns(prompt, w_width).length * 32 + 32
       super((640 - w_width) / 2, (480 - w_height) / 2, w_width, w_height)
       self.contents = Bitmap.new(width - 32, height - 32)
       @prompt = mk_lns(prompt, width)
       @rtrn_var = rtrn_var
       @choice = 0

       loop do
           Graphics.update
           Input.update
           update
           break unless self
       end
   end

   def update
       @choice = @choice == 1 ? 0 : 1 if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
       self.cursor_rect.set(@choice * (width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32)
       if Input.trigger?(Input::C)
           eval("#{@rtrn_var}=" + (@choice == 1).to_s)
           $game_system.se_play($data_system.decision_se) if @choice == 1
           $game_system.se_play($data_system.cancel_se) if @choice == 0
           dispose
       end
       refresh
   end

   def refresh
       for i in 0...@prompt.length
           t_width = self.contents.text_size(@prompt[i])[0]
           self.contents.draw_text(Rect.new(0, i * 32, t_width, 32), @prompt[i])
       end
       self.contents.draw_text(Rect.new(0, @prompt.length * 32 + 8, (width - 32) / 2, 32), "Yes", 1)
       self.contents.draw_text(Rect.new((width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32), "No", 1)
   end

   def mk_lns(txt, txt_width)
       tmp_bit = Bitmap.new(1, 1)
       lns = []
       text_array = txt.split(/ /)
       ln = ""
       while text_array != []
           ln += text_array.shift
           if tmp_bit.text_size(ln)[0] > txt_width - 32
               if ln.split(/ /).length == 1
                   tmp = ""
                   while tmp_bit.text_size(ln)[0] > txt_width - 32
                       tmp += ln[0..0]
                       ln[0..0] = ""
                   end
                   text_array.unshift(tmp)
               else
                   ln = ln.split(/ /)
                   ln.pop
                   ln = ln.join(" ")
               end
               lns.push(ln)
               ln = ""
           end
       end
       return lns
   end
end

 

Edited by Thallion

Share this post


Link to post
Share on other sites

Sorry, it's hard making a script w/o the program it's for. Go to lines 46 and 49 and change where it says:

tmp_bit.text_size(ln)[0]

to:

tmp_bit.text_size(ln).width

Share this post


Link to post
Share on other sites

The text can't be empty.

Bitmap's need a size of at least one, although Enterbrain did make an error and allow for some Bitmap sizes to have negative values without throwing an exception.

Share this post


Link to post
Share on other sites

Alright, I forgot to add the final line of text into my array of lines.

 

class Window_Dialog < Window_Base
   def initialize(prompt, rtrn_var, w_width = 480)
       w_height = mk_lns(prompt, w_width).length * 32 + 32
       super((640 - w_width) / 2, (480 - w_height) / 2, w_width, w_height)
       self.contents = Bitmap.new(width - 32, height - 32)
       @prompt = mk_lns(prompt, width)
       @rtrn_var = rtrn_var
       @choice = 0

       loop do
           Graphics.update
           Input.update
           update
           break unless self
       end
   end

   def update
       @choice = @choice == 1 ? 0 : 1 if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
       self.cursor_rect.set(@choice * (width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32)
       if Input.trigger?(Input::C)
           eval("#{@rtrn_var}=" + (@choice == 1).to_s)
           $game_system.se_play($data_system.decision_se) if @choice == 1
           $game_system.se_play($data_system.cancel_se) if @choice == 0
           dispose
       end
       refresh
   end

   def refresh
       for i in 0...@prompt.length
           t_width = self.contents.text_size(@prompt[i])[0]
           self.contents.draw_text(Rect.new(0, i * 32, t_width, 32), @prompt[i])
       end
       self.contents.draw_text(Rect.new(0, @prompt.length * 32 + 8, (width - 32) / 2, 32), "Yes", 1)
       self.contents.draw_text(Rect.new((width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32), "No", 1)
   end

   def mk_lns(txt, txt_width)
       tmp_bit = Bitmap.new(1, 1)
       lns = []
       text_array = txt.split(/ /)
       ln = ""
       while text_array != []
           ln += text_array.shift
           if tmp_bit.text_size(ln).width > txt_width - 32
               if ln.split(/ /).length == 1
                   tmp = ""
                   while tmp_bit.text_size(ln).width > txt_width - 32
                       tmp += ln[0..0]
                       ln[0..0] = ""
                   end
                   text_array.unshift(tmp)
               else
                   ln = ln.split(/ /)
                   ln.pop
                   ln = ln.join(" ")
               end
               lns.push(ln)
               ln = ""
           end
       end
       lns.push(ln) if ln != ""
       return lns
   end
end

 

Share this post


Link to post
Share on other sites

Go to that line and replace:

self.contents.text_size(@prompt[i])[0]

with:

self.contents.text_size(@prompt[i]).width

Share this post


Link to post
Share on other sites

I'm so sorry that I missed so many errors. Here is the probably fixed script.

 

class Window_Dialog < Window_Base
   def initialize(prompt, rtrn_var, w_width = 480)
       w_height = mk_lns(prompt, w_width).length * 32 + 32
       super((640 - w_width) / 2, (480 - w_height) / 2, w_width, w_height)
       self.contents = Bitmap.new(width - 32, height - 32)
       z-index = -100
       @prompt = mk_lns(prompt, width)
       @rtrn_var = rtrn_var
       @choice = 0

       loop do
           Graphics.update
           Input.update
           break unless self
           update
       end
   end

   def update
       @choice = @choice == 1 ? 0 : 1 if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
       self.cursor_rect.set(@choice * (width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32)
       if Input.trigger?(Input::C)
           eval("#{@rtrn_var}=" + (@choice == 1).to_s)
           $game_system.se_play($data_system.decision_se) if @choice == 1
           $game_system.se_play($data_system.cancel_se) if @choice == 0
           dispose
       end
       refresh
   end

   def refresh
       for i in 0...@prompt.length
           t_width = self.contents.text_size(@prompt[i]).width
           self.contents.draw_text(Rect.new(0, i * 32, t_width, 32), @prompt[i])
       end
       self.contents.draw_text(Rect.new(0, @prompt.length * 32 + 8, (width - 32) / 2, 32), "Yes", 1)
       self.contents.draw_text(Rect.new((width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32), "No", 1)
   end

   def mk_lns(txt, txt_width)
       tmp_bit = Bitmap.new(1, 1)
       lns = []
       text_array = txt.split(/ /)
       ln = []
       while text_array != []
           ln.push(text_array.shift)
           if tmp_bit.text_size(ln).width > txt_width - 32
               if ln.split(/ /).length == 1
                   tmp = ""
                   ln = ln[0]
                   while tmp_bit.text_size(ln).width > txt_width - 32
                       tmp += ln[0..0]
                       ln[0..0] = ""
                   end
                   text_array.unshift(tmp)
               else
                   ln.pop
                   ln = ln.join(" ")
               end
               lns.push(ln)
               ln = []
           end
       end
       lns.push(ln.join(" ")) if ln != ""
       return lns
   end
end

 

Share this post


Link to post
Share on other sites

change:

tmp_bit.text_size(ln)

to:

tmp_bit.text_size(ln.join(" "))

Edited by Thallion

Share this post


Link to post
Share on other sites

same problem with that video :dl.dropbox.com/u/93827519/SRFile2012_8_1_22_26_29_225.avi

 

but this error comes at the end:

 

qOGJw.png

Share this post


Link to post
Share on other sites

You are trying to do a strange combination of a scene and a window in the same class.

 

 

   def update
    @choice = @choice == 1 ? 0 : 1 if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
    self.cursor_rect.set(@choice * (width - 32) / 2, @prompt.length * 32 + 8, (width - 32) / 2, 32)
    if Input.trigger?(Input::C)
	    eval("#{@rtrn_var}=" + (@choice == 1).to_s)
	    $game_system.se_play($data_system.decision_se) if @choice == 1
	    $game_system.se_play($data_system.cancel_se) if @choice == 0
	    dispose
    end
    refresh
   end

 

That's going to cause an error every time, it refreshes the window after disposing. Disposing a window does not set it to nil, it merely disposes its resources, but the handle remains, hence the "disposed?" method that you can use on it.

 

 

Also, this:

 

    loop do
	    Graphics.update
	    Input.update
	    break unless self
	    update
    end

 

This loop will not end unless the window is nil. If it is anything but, even disposed it will continue to loop. A better line of code using the same implementation would be:

 

break if self == nil || self.disposed?

Share this post


Link to post
Share on other sites

i was bored so i put these together biggrin.png

scene_title

 

 

#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing.
#==============================================================================
class Scene_Title
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 def main
   # If battle test
   if $BTEST
  battle_test
  return
   end
   # Load database
   $data_actors	    = load_data("Data/Actors.rxdata")
   $data_classes	   = load_data("Data/Classes.rxdata")
   $data_skills	    = load_data("Data/Skills.rxdata")
   $data_items		 = load_data("Data/Items.rxdata")
   $data_weapons	   = load_data("Data/Weapons.rxdata")
   $data_armors	    = load_data("Data/Armors.rxdata")
   $data_enemies	   = load_data("Data/Enemies.rxdata")
   $data_troops	    = load_data("Data/Troops.rxdata")
   $data_states	    = load_data("Data/States.rxdata")
   $data_animations    = load_data("Data/Animations.rxdata")
   $data_tilesets	  = load_data("Data/Tilesets.rxdata")
   $data_common_events = load_data("Data/CommonEvents.rxdata")
   $data_system	    = load_data("Data/System.rxdata")
   # Make system object
   $game_system = Game_System.new
   # Make title graphic
   @sprite = Sprite.new
   @sprite.bitmap = RPG::Cache.title($data_system.title_name)
   # Make command window
   s1 = "New Game"
   s2 = "Continue"
   s3 = "Shutdown"
   @command_window = Window_Command.new(192, [s1, s2, s3])
   @command_window.back_opacity = 160
   @command_window.x = 320 - @command_window.width / 2
   @command_window.y = 288
   @choice_window = Window_Choice.new
   @choice_window.x = 320 - @choice_window.width / 2
   @choice_window.y = 288
   @choice_window.back_opacity = 160
   # Continue enabled determinant
   # Check if at least one save file exists
   # If enabled, make @continue_enabled true; if disabled, make it false
   @continue_enabled = false
   for i in 0..3
  if FileTest.exist?("Save#{i+1}.rxdata")
    @continue_enabled = true
  end
   end
   # If continue is enabled, move cursor to "Continue"
   # If disabled, display "Continue" text in gray
   if @continue_enabled
  @command_window.index = 1
   else
  @command_window.disable_item(1)
   end
   # Play title BGM
   $game_system.bgm_play($data_system.title_bgm)
   # Stop playing ME and BGS
   Audio.me_stop
   Audio.bgs_stop
   # Execute transition
   Graphics.transition
   # Main loop
   loop do
  # Update game screen
  Graphics.update
  # Update input information
  Input.update
  # Frame update
  update
  # Abort loop if screen is changed
  if $scene != self
    break
  end
   end
   # Prepare for transition
   Graphics.freeze
   # Dispose of command window
   @command_window.dispose
   # Dispose of title graphic
   @sprite.bitmap.dispose
   @sprite.dispose
   @choice_window.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   if @command_window.active
  # Update command window
  @command_window.update
  # If C button was pressed
  if Input.trigger?(Input::C)
    # Branch by command window cursor position
    case @command_window.index
    when 0  # New game
	  for i in 0..3
	    if FileTest.exist?("Save#{i + 1}.rxdata")
		  @choice_window.active = true
		  @choice_window.visible = true
		  @command_window.active = false
		  @command_window.visible = false
		  break
	    else
		  command_new_game
	    end
	  end
    when 1  # Continue
	  command_continue
    when 2  # Shutdown
	  command_shutdown
    end
  end
   else #command window is inactive
  @choice_window.update
   if Input.trigger?(Input::B)
    @choice_window.index = 1
    @choice_window.active = false
    @choice_window.visible = false
    @command_window.active = true
    @command_window.visible = true
    @choice_window.update
  end
  # If C button was pressed
  if Input.trigger?(Input::C)
    case @choice_window.index
    when 0
	  command_new_game
    when 1
	  @choice_window.active = false
	  @choice_window.visible = false
	  @command_window.active = true
	  @command_window.visible = true
    end
  end
   end
 end
end

 

 

scene_end

 

 

#==============================================================================
# ** Scene_End
#------------------------------------------------------------------------------
#  This class performs game end screen processing.
#==============================================================================
class Scene_End
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 def main
# Make command window
s1 = "To Title"
s2 = "Shutdown"
s3 = "Cancel"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 240 - @command_window.height / 2
@choice_window = Window_Choice.new
@choice_window.x = 320 - @choice_window.width / 2
@choice_window.y = 240 - @choice_window.height / 2
@choice_window.z = 200
# Execute transition
Graphics.transition
# Main loop
loop do
  # Update game screen
  Graphics.update
  # Update input information
  Input.update
  # Frame Update
  update
  # Abort loop if screen is changed
  if $scene != self
	break
  end
end
# Prepare for transition
Graphics.freeze
# Dispose of window
@command_window.dispose
@choice_window.dispose
# If switching to title screen
if $scene.is_a?(Scene_Title)
  # Fade out screen
  Graphics.transition
  Graphics.freeze
end
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
if @command_window.active
  # Update command window
  @command_window.update
  # If B button was pressed
  if Input.trigger?(Input::B)
	# Play cancel SE
	$game_system.se_play($data_system.cancel_se)
	# Switch to menu screen
	$scene = Scene_Menu.new(5)
	return
  end
  # If C button was pressed
  if Input.trigger?(Input::C)
	# Branch by command window cursor position
	case @command_window.index
	when 0  # to title
	  @command_window.active = false
	  @choice_window.active = true
	  @choice_window.visible = true
	when 1  # shutdown
	  @command_window.active = false
	  @choice_window.active = true
	  @choice_window.visible = true
	when 2  # quit
	  command_cancel
	end
	return
  end
else # command window not active
  @choice_window.update
  if Input.trigger?(Input::B)
	@choice_window.active = false
	@choice_window.visible = false
	@command_window.active = true
	@choice_window.index = 1
	@choice_window.update
  end
  # If C button was pressed
  if Input.trigger?(Input::C)
	case @command_window.index
	when 0  # to title
	  case @choice_window.index
	  when 0 #yes
		  command_to_title
	  when 1 #no
		@command_window.active = true
		@choice_window.active = false
		@choice_window.visible = false
	  end
	  command_to_title
	when 1  # shutdown
	  case @choice_window.index
	  when 0 #yes
		command_shutdown
	  when 1 #no
		@command_window.active = true
		@choice_window.active = false
		@choice_window.visible = false
	  end
	end
  end
  return
end
 end
end

 

 

and finally window_choice

 

 

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * Class Window_Choice(this creates the choice input Window)
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Window_Choice < Window_Base
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 # * Public instance variables
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 attr_accessor :index
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 # Initialize
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 def initialize
super(0, 0, 192, 128)
self.contents = Bitmap.new(width - 32, height - 32)
self.visible = false
self.active = false
@index = 1
refresh
 end
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 # def index
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 def index=(index)
@index = index
# Update cursor rectangle
update_cursor_rect
 end
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 # Frame update
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 def update
if Input.trigger?(Input::LEFT)
  @index -= 1 if @index > 0
end
if Input.trigger?(Input::RIGHT)
  @index += 1 if @index < 1
end
update_cursor_rect
refresh
 end
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 # update_cursor_rect
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 def update_cursor_rect
x = 4 + @index % 2 * 76
self.cursor_rect.set(x, 50, 76, 32)
 end
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 # refresh
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
 def refresh
self.contents.clear
text = "Are you sure?"
cx = contents.text_size(text)
self.contents.draw_text((160 - cx.width) / 2, 4, cx.width, cx.height, text)
for i in 0..1
  text = "Yes" if i == 0
  text = "No" if i == 1
  cx = contents.text_size(text).width
  centre = (76 - cx) / 2
  x = (4 + centre) + i % 2 * 76
  self.contents.draw_text(x, 50, cx, 32, text)
end
 end
end

 

 

its not as fancy as thallion's with the arrays and what not blink.png but it works none the less biggrin.png

edit: changed scene title to check for save files :)

Edited by diagostimo

Share this post


Link to post
Share on other sites

It's not my script, diagostimo should get credit. For what it's worth, I fixed the error... And then saw ForeverZer0's post telling me how.

 

Btw, ForeverZer0, I was just putting in the loop to stop anything else from updating while the window was up.

And zahraa, was the scene_end command window still in front of the dialog?

Edited by Thallion

Share this post


Link to post
Share on other sites

There is nothing really wrong with the idea of the loop, it was just executed incorrectly. Not even the loop itself, but how you handled disposing. I am sure a minor edit could everything, just alter how you close/dispose the window.

Share this post


Link to post
Share on other sites

i know this is not your script.i just told "you did your best too".

i asked diagostimo for credit because i am not exactly sure who wrote it

and yes,it was front of the dialog

Edited by zahraa

Share this post


Link to post
Share on other sites

I would have went with something simpler. You can use it for anything you want to "confirm" even. Just use "Confirm_Dialog.show", and it will return a true/false, but suspend processing at the current line.

 

module Confirm_Dialog

 def self.show
   base = Window_Base.new(224, 160, 192, 64)
   base.contents = Bitmap.new(base.width - 32, base.height - 32)
   base.contents.draw_text(0, 0, base.contents.width, 32, 'Are you sure?')
   commands = Window_Command.new(192, ['Yes', 'No'])
   commands.x, commands.y, base.z, commands.z = 224, 224, 9999, 9999
   commands.active, commands.index = true, 0
   loop {
  Graphics.update
  Input.update
  commands.update
  break if Input.trigger?(Input::C)
   }
   result = commands.index == 0
   base.dispose
   commands.dispose
   return result
 end
end

class Scene_Load

 alias confirm_on_decision on_decision
 def on_decision(filename)
   return unless Confirm_Dialog.show
   confirm_on_decision(filename)
 end
end
class Scene_End

 alias confirm_update update
 def update
   if Input.trigger?(Input::C)
  return unless Confirm_Dialog.show
   end
   confirm_update
 end
end

Share this post


Link to post
Share on other sites

I would have went with something simpler. You can use it for anything you want to "confirm" even. Just use "Confirm_Dialog.show", and it will return a true/false, but suspend processing at the current line.

 

Oh, most of my trouble was in my code to seperate the text of the dialog into lines. I made it so you could have different text for different scenarios. However, I like most of your code better than how I tried to do it.

Share this post


Link to post
Share on other sites

Yeah, my code is pretty static in that it only shows one set of text. It would only take a minor edit to be able to supply arguments for what text is used, but I was lazy; I only spent 2 minutes on the whole thing.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...