Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Hi, trying to get out of a custom scene I made.

Bogurd

Member

I made a custom battle scene, and when the players get a victory and $scene is set to scene_map, it sets it, but
then continues to carry out the code in the battle script, which $scene isn't anymore. Does anyone know how to
get a clean transition back into scene map with the following script? (2 Notes, ignore the print statements in there,
and assume that there are two other battle_screen scripts, but this one is the actual system.)

Code:
 

#sprite_instance.animation($data_animations[ANIMATION_ID], HIT_FLAG)

#Time to get the fighting in!

#Central Battle screen. Main functions are controlled from here.

class Battle_Screen

  def main

  #handles the backround graphic, checks to see which to initialize

   #set up grid object

    @grid=Battle::grid

    #get round objects

    @round=Battle::round

    @perm_round=Battle::round

    @end_treasure=[]

    #initialize the two halves of the backround

    @background_l=Sprite.new

    @background_r=Sprite.new

    @background_l.z,@background_r.z=100,100

    @animation_progression=0

  #Initialize a battle bgm based on the battle type

    case $battle_bgm

    #Regular Battle

    when 1

      BGM_Access::bgm_play(2,100,65)

      @victory_me="Audio/ME/001-Victory01"

    #Boss 1

    when 2

      

    end#case

   

    case $background_graphic

    when 1

      #put the file name on another line to cut down on line length

        @b_definer=rand(2)

        case @b_definer

        when 0

        @file_l="Graphics/Battlebacks/XP_Battle_Plains01_L"

        @file_r="Graphics/Battlebacks/XP_Battle_Plains01_R"

        when 1

          @file_l="Graphics/Battlebacks/XP_Battle_Plains02_L"

          @file_r="Graphics/Battlebacks/XP_Battle_Plains02_R"

        when 2

          @file_l="Graphics/Battlebacks/XP_Battle_Plains03_L"

          @file_r="Graphics/Battlebacks/XP_Battle_Plains03_R"

        end#case

     when 2 #002 sunny forest backround

       @file_l="Graphics/Battlebacks/XP_Battle_Plains02_L"

       @file_r="Graphics/Battlebacks/XP_Battle_Plains02_R"

     when 25

       @file_l="Graphics/Battlebacks/XP_Battle_Castle01_L"

       @file_r="Graphics/Battlebacks/XP_Battle_Castle01_R"

   end#case

        @background_l.bitmap=Bitmap.new(@file_l)

        @background_l.y=0

        @background_l.ox,@background_l.oy=0,0

        @background_l.x=-320

        @background_r.bitmap=Bitmap.new(@file_r)

        @background_r.ox,@background_r.oy=0,0

        @background_r.y=0

        @background_r.x=640

    #this shoves the two backrounds together for effect!

      for i in 0...32

          @background_l.x+=10

          @background_r.x-=10

          Wait::wait(3)

        end#for

    #place and initialize combatant hero sprites

    for i in 0...$game_data.party.size

      $game_data.party[i].battler=Battle_Sprite.new

    #place the battlers according to the grid

      @x,@y=i*@grid[i+12].origin_x+8,@grid[i*3].origin_y+8

      $game_data.party[i].battler.set($game_data.party[i].battle_graphic_r,@x,@y)

      $game_data.party[i].battler.z=2990

    end#for loop

    #place adversaries

    for i in 0...$encounter.size

      $encounter[i].battler=Battle_Sprite.new

      $encounter[i].battler.set($encounter[i].battle_graphic_l,0,0)

      $encounter[i].battler.z=2990

      case $enemy_battle_formation

        when 1

          Battle::stellen($encounter[i].battler,@grid[270+15*i])

       when 2

          Battle::stellen($encounter[i].battler,@grid[240+15*i])

       end#case

     end#for

     #display battle tabs

    @btabs=[]

    #Tab checker array

    for i in [email=0...@round.size]0...@round.size[/email]

      @btabs[i]=Sprite.new

      @btabs[i].bitmap=Bitmap.new("Graphics/Pictures/"+@round[i].battle_tab)

      @btabs[i].x=20+10*Math::tan(i)

      @btabs[i].y=20+18*i

      @btabs[i].z=3000

    end#for

    #battle formation time!

     #Set the new round flag to true

     @new_round=true

     #initialize windows

      #standard graphics/input loop

      loop do

      Graphics.update

      Input.update

      update

      if $scene!=self

        break

      end#if

    end#loop do

    end#main func

  #Crentral Battle Loop (Must be constantly revisited)

  

  #update-------------Runs every round----------------------------------

  def update

    Graphics.update

    #go to the beginning of round_route for a new round

    #tabs

    for k in [email=0...@round.size]0...@round.size[/email]

      @btabs[k]=Sprite.new

      @btabs[k].bitmap=Bitmap.new("Graphics/Pictures/"+@round[k].battle_tab)

      #Make an exotic x placing pattern x(i)

      @btabs[k].x=24+10*Math::tan(Math::sin(k+(k/(1+k))))

      #y(i) needs to have reasonable spacing

      @btabs[k].y=20+18*k

      @btabs[k].z=9990

    end#for

    #main round loop

   if @new_round==true then @round=@perm_round end

   for m in [email=0...@round.size]0...@round.size[/email]

    #Run the system checks -RTSC

    turn?

    still_defending?

    faint?

    @advs=[]

    for i in 0...@perm_round.size

      if @perm_round[i].is_a? Adversary then @advs.push @perm_round[i] end

    end

    if @advs.empty?

      Audio.me_play(@victory_me,100,125) 

      BGM_Access::bgm_fade(3,100,false)

      BGM_Access::bgm_play(2,100,80)

      #Spoils calculations

      @stat_points,@magic_points,@currency=0,0,0

      for i in 0...$encounter.size

        @stat_points+=$encounter[i].stat_points

        @magic_points+=$encounter[i].magic_points

        @currency+=$encounter[i].currency

        @victory_swindow=Sprite_Window.new

        @victory_swindow.z=1000

        @victory_swindow.opacity=155

        @victory_swindow.slide_oppcorner(160+260,80+160,"Graphics/Pictures/Window_Victory")

        #(160-16,80-16,260+64,160+32)

        @end_treasure.push $game_data.items[0]

        @victory_window=Window_Victory.new(@currency,@stat_points,@magic_points,@end_treasure)

        #Everyone's gotta share the spoils!

        @divstats=(@stat_points/$game_data.party.size).to_i

        @divmagic=(@magic_points/$game_data.party.size).to_i

        $game_data.currency+=@currency

      end# for i #1

      for j in 0...$game_data.party.size

        $game_data.party[j].stat_points+=@divstats

        $game_data.party[j].magic_points+=@divmagic

      end# for j #1

        #One time animation

        for k in 0...3

          $game_data.party[j].battler.act(7,k)

        end#for

        for l in 3...0

          $game_data.party[j].battler.act(7,l)

        end#for

        #wait for A to be pressed.

      loop do

      if @victory_window.curr_rep != nil

        @victory_window.curr_rep.update

      end

        for i in 0...@victory_window.icons.size

          if @victory_window.icons[i]!=nil

          @victory_window.icons[i].update

          end

        end

        animate

      if Input.press?(Input::A)

        SE_Access::se_play(2,100,120)

        @victory_window.curr_rep.dispose

        @victory_window.dispose

        @victory_swindow.sich_zerstoeren_x

        @victory_swindow.dispose

        close_out

        $scene=Scene_Map.new

        p ""

        break

      end#for

      end#if

    end#loop

    #If the current round element is a hero, run the hero's turn function

    #passing in the hero object

    if @round[m]!=nil

    if @round[m].is_a? Hero then hero_round(@round[m]) end

    #If the current round element is an adversary, run the adversary's turn 

    #function passing in the adversary object

    if @round[m].is_a? Adversary then adversary_round(@round[m]) end

    end#if nil

          #dispose tabs for update

        for j in [email=0...@btabs.size]0...@btabs.size[/email]

          @btabs[j].dispose

        end#for

        #Somehow deleting an element from @round does 

        #it to @perm_round automatically also

      end#for loop

      

  end#update func

  

  #end of update-------------------------------------------------

  

  #Hero Round Function

  def hero_round(hero)

    @hero=hero

    @hero_stats_sw=Sprite_Window.new

    @hero_stats_sw.opacity=155

    @hero_stats_sw.slide(160,240-160,"Graphics/Pictures/Window_Heroturn")

    @hero_status_w=Window_Heroturn.new(@hero)

    @selectorxy=Selector_XY.new(2,3,105,20)

    @selectorxy.set(0,0,1,"Graphics/Pictures/Selector_Arrowy1",0,190-26,190-12)

    #begin hero turn input processing await loop

    loop do

      animate

      #Put in loop animation blinking here

      Graphics.update

      Input.update

      @animation_progression+=1

      @animation_progression%=4

      @selectorxy.beweg

      @choicex,@choicey=@selectorxy.index_x,@selectorxy.index_y

      if Input.press?(Input::A)

        hero_command(@hero)

        return

        break

        end#input cond

    end#loop do

  end#hero_round

  

  #Routes the compiler to the correct hero act method

  

  

   #simaltamiously animates battlers

  def animate

    for i in 0...$game_data.party.size

      if $game_data.party[i].battler != nil

      $game_data.party[i].battler.animate(@animation_progression)

      end

    end

    #Somehow @perm_round is losing objects before its supposed to

    for i in 0...@perm_round.size

      if @perm_round[i].tag=="adversary"

      if @perm_round[i] != nil

      if @perm_round[i].battler != nil

      @perm_round[i].battler.animate(@animation_progression)

      end end end

    end

  end#animate

  #Hero go func

  def hero_command(hero)

    @hero=hero

    if @choicex==0&&@choicey==0 then hero_attack_prep(@hero) end

    if @choicex==1&&@choicey==0 then hero_move(@hero) end

    if @choicex==0&&@choicey==1 then defend(@hero) end

    if @choicex==1&&@choicey==1 then item_use(@hero) end

    if @choicex==0&&@choicey==2 then hero_magic(@hero) end

    if @choicex==1&&@choicey==2 then escape end

  end#hero_command

 

  #Adversary Round Function

  def adversary_round(adversary)

    @adversary=adversary

    @adv_target=rand($game_data.party.size)

    AI::route(@adversary)

    #Defend

    if AI::route(@adversary)==1 then defend(@adversary) end

    #Attack

    if AI::route(@adversary)==2 then attack(@adversary,$game_data.party[@adv_target]) end

    #Run to safety

    if AI::route(@adversary)==3 then move_to(@adversary,480-@adversary.battler.frame_w,320) end

    return

  end#adversary round

  #Cecks to see if anyone is dead

  def faint?

    #Iterates thru the permenant round array for that battle

    for i in 0...@perm_round.size

      #Faint Handler

      if @perm_round[i]!=nil

      if @perm_round[i].hp<=0

        @fainter=@perm_round[i]

        for j in 0...3

        @fainter.battler.act(2,j)

        end

        

      #Only adversaries collapse at faint, and drop their item.

        if @perm_round[i].tag=="adversary" 

          @perm_round[i].battler.collapse 

          drop_item?(@perm_round[i])

        end

        SE_Access::battle_se_play(@perm_round[i].faint_sfx,125)

        @overkill=Math::abs(0-@perm_round[i].hp)

        if @overkill>0

        Graphic::super_msg("Woerter_Overkill")

        Graphic::quantity_display(@overkill,@perm_round[i].battler,2) end #if overkill..

        if @perm_round[i].tag=="adversary"

        for k in 0...20

          @perm_round[i].battler.y-=20

          Wait::wait(3)

        end

        @perm_round[i].battler.dispose

        @perm_round[i].battler=nil

        @perm_round[i]=nil

        @perm_round.delete_at i

        end

      end#if

      end#if nil

    end#for outter

  end#faint?

  #Makes the heros and adversaries turn when necessary

  def turn?

    #Get the directory filename stem

    @fp="Graphics/Battlers/"

    #Fill an array of adversaries

    @advs2=[]

    for k in 0...@perm_round.size

      if @perm_round[k].tag=="adversary" then @advs2[k]=@perm_round[k] end

    end#for perm (1)

    #Fill an array of not dead heros

    Game_Procedure::nil_kickout(@advs2)

    #Check to see if a hero needs to be turned around

    for i in 0...$game_data.party.size

        #Checks to see if the closest adversary to hero i is left of hero i

       if Battle::closest_opponent($game_data.party[i],@advs2)<=$game_data.party[i].battler.x  

          $game_data.party[i].battler.bitmap=Bitmap.new(@fp+$game_data.party[i].battle_graphic_l)

          animate

        end#if(1,1)

        if Battle::closest_opponent($game_data.party[i],@advs2)>$game_data.party[i].battler.x

          $game_data.party[i].battler.bitmap=Bitmap.new(@fp+$game_data.party[i].battle_graphic_r)

          

          animate

        end#if (1,2)

      end#for heros

      #Checks to see if the closest adversary to hero i is left of hero i

    for j in [email=0...@advs2.size]0...@advs2.size[/email]

      if Battle::closest_opponent(@advs2[j],$game_data.party)<=@advs2[j].battler.x  

          #@advs2[j].battler.bitmap=Bitmap.new(@fp+@advs2[j].battle_graphic_r)

          #animate

        end#if(1,1)

        if Battle::closest_opponent(@advs2[j],$game_data.party)>@advs2[j].battler.x

          @advs2[j].battler.bitmap=Bitmap.new(@fp+@advs2[j].battle_graphic_l)

          animate

        end#if (1,2)

    end#for j

  end#turn?

  #Checks to see if the defend should be canceled.

  def still_defending?

    #Check to see if the defend attribute is turned off. (The lower the agility,

    #the longer the defend can be handled.)

    for i in 0...@perm_round.size

      @perm_round[i].defend_rounds-=1

      if @perm_round[i].defend_rounds<=0

        @perm_round[i].defend_rounds=0

        @perm_round[i].battler.offset_y=0

        @perm_round[i].defending=false

      end#if

    end#for

    return

  end#still_defending?

  #Check to see if the player has won the battle and handle spoils

  

  #Check to see if the adversary drops their item.

  def drop_item?(adv)

    @adversary=adv

    #

    @chance_treasure=rand(100)

    if @chance_treasure>=0&&@chance_treasure<@adversary.chance_drop

      @end_treasure.push @adversary.item_dropped

    end#if

  end#drop_item?()

  

  #Close the scene, dispose of objects and jump back to previous zone

  def close_out

    @background_l.dispose

    @background_r.dispose

    for i in 0...$game_data.party.size

      $game_data.party[i].battler.dispose

      $game_data.party[i].battler=nil

    end

    for i in [email=0...@btabs.size]0...@btabs.size[/email]

      @btabs[i].dispose

    end

  end#close+out

end#class

 

 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top