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.

Syntax Error?

Hey. I'm making a script addon for XAS Hero Edition 2, and I've gotten most of the code done. But I'm getting a syntax error when I try and run the project. I fixed all the ones I could find, but I don't see anymore. Also, there are a few things dependent on another script, and those scripts require the proper graphics, so I have to supply the whole project file to enable you to see what's wrong

http://celenath.com/files/XAS_Hero_2[LB].zip

Thanks for helping!
 

khmp

Sponsor

In short aliasing is being done backwards. And aliasing does not start a code block so it doesn't require an "end". You are also aliasing the same method over and over. You can just have extra methods that are called from the aliased update. On one line you have a conditional which stretches over a bunch of lines. And they can as long as the previous line has an operator on it as the very last thing. For example:

Code:
a, b = 1, 0
if (a == b
  || a >= b) # Illegal
  # do work
end


Code:
a, b = 1, 0
if (a == b || 
    a >= b) # Legal
  # do work
end

I think your whole script could use some revisions to get rid of unnecessary code. I would be glad to help you on it. But anywhere here it is for you.
Code:
#------------------------------------------------------------------------------
# On map party switch                  
# By Legacyblade
#------------------------------------------------------------------------------

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Configuration
#
#
# With the configuration, you can do the following
#
# Select a switch number to allow and disallow the switching of party members
# Select a switch number to disable the automatic gameover when all party
# memer have died
#
# Remember, Aleworks Input Module is included with the script, so you can use
# any key you want.
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#The running key
PSWITCH_BUTTON = [Keys::E]

#The disable party switching game switch number
PSWITCH_NUM = 1

#The switch to be flipped when all party members are dead
GOVER_FLIP = 2

#The automatic gameover game switch number. If it is disabled, 
GOVER_CHECK = 3

class Scene_Map
  
  alias_method :lebl_party_switch_update, :update 
  def update
    
    dead_or_alive
    leader_dead
    
    # check if party switching is enabled, and the player has pressed the party
    # switch button
    if($game_switches[PSWITCH_NUM] == false && 
      Input.trigger?(PSWITCH_BUTTON) && @liveParty.size > 1)
    # shift the current leader to the back
      id = @liveParty[0].id
      $game_party.remove_actor(id)
      $game_party.add_actor(id)
    # Refresh the XAS hud
      $game_system.xas_skill_id = 0
      $game_temp.skill_refresh = true
    end
    lebl_party_switch_update
  end

  def dead_or_alive
    @liveParty = []
    @deadParty = []
    
    for i in 0...$game_party.actors.size
      #if a party member has at least 1 hp, add him to the liveParty array
      if $game_party.actors[i].hp >= 1
        #check to see if the liveParty has anything in it, and if not,
        #initialize the liveParty index counter
        if @liveParty.size == 0
          n = 0
        end
        #put the proper actor in thier liveParty array location and updated
        #the liveParty index counter
        @liveParty[n] = $game_party.actors[i]
        n = n + 1
      #if a party member doesn't have at least 1 hp, add him to the deadParty
      #array
      else
        #check to see if the deadParty has anything in it, and if not,
        #initialize the deadParty index counter
        if @deadParty.size == 0
          p = 0
        end
        #put the proper actor in thier deadParty array location and updated
        #the deadParty index counter
        @deadParty[n] = $game_party.actors[i]
        p = p + 1
      end
    end
  end
  
  def leader_dead
    #Check if the lead actor is out of HP
    if @liveParty[0].hp == 0
      #call the sort DA method to make sure the arrays are updated before
      #proceeding
      sort_DA
      #Check if the liveParty array is less than one, and that gameovers
      #will be called
      if @liveParty[0].size < 1 && $game_switches[GOVER_CHECK] == false
        #call the gameover
        $scene = Scene_Gameover.new
      #Check if the liveParty array is less than one, but that gameovers
      #will not be called
      elsif @liveParty[0].size < 1 && $game_switches[GOVER_CHECK] == true
        #flip the gameover handeling switch for the player
        $game_switches[GOVER_CHECK] == true
      end  
    end
  end
end

Good luck with it legacyblade! :thumb:
 
Ok, I'm getting closer to a working one. But right now I'm getting an error

Whenever I push the party switching button, it says

Script 'LB - PartySwitch' line 90: NoMethodError occurred.

undefined method '+' for nil:NilClass

I took out the few lines that make it need the other scripts, so I just am posting the script this time.

Code:
#------------------------------------------------------------------------------
# On map party switch                  
# By Legacyblade
#------------------------------------------------------------------------------

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Configuration
#
#
# With the configuration, you can do the following
#
# Select a switch number to allow and disallow the switching of party members
# Select a switch number to disable the automatic gameover when all party
# memer have died
#
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#The running key
PSWITCH_BUTTON = Input::L

#The disable party switching game switch number
PSWITCH_NUM = 1

#The switch to be flipped when all party members are dead
GOVER_FLIP = 2

#The automatic gameover game switch number. If it is turned on, it overides the
#normal game over checking, and flips a switch when the party is out of HP.
GOVER_OR = 3



class Scene_Map

  
  
  alias_method :lebl_party_switch_update, :update 
  def update

    $liveParty = Array.new($game_party.actors.size)
    $deadParty = Array.new($game_party.actors.size)
    
    dead_or_alive
    leader_switch
    check_hp_out
    all_p_dead
    
    # check if party switching is enabled, and the player has pressed the party
    # switch button
    if $game_switches[PSWITCH_NUM] == false && Input.trigger?(PSWITCH_BUTTON)
      @switchLeader = 1
    end
    lebl_party_switch_update
  end
  
  def dead_or_alive
    
    for i in 0...$game_party.actors.size
      #if a party member has at least 1 hp, add him to the liveParty array
      if $game_party.actors[i].hp > 0
        #check to see if the liveParty has anything in it, and if not,
        #initialize the liveParty index counter
        if $liveParty[0] == nil
          @n = 0
        end
        #put the proper actor in thier liveParty array location and updated
        #the liveParty index counter
        $liveParty[@n] = $game_party.actors[i]
        @n = @n + 1
      #if a party member doesn't have at least 1 hp, add him to the deadParty
      #array
      else
        #check to see if the deadParty has anything in it, and if not,
        #initialize the deadParty index counter
        if $deadParty[0] == nil
          @p = 0
        end
        #put the proper actor in thier deadParty array location and updated
        #the deadParty index counter
        $deadParty[@p] = $game_party.actors[i]
        @p = @p + 1
      end
    end
  end
  def leader_switch
    if @switchLeader == 1
    # shift the current leader to the back
      for i in 0...$liveParty.size
        if $liveParty[i] != nil
          @liveLength = @liveLength + 1
        end
      end
      tmp = $liveParty[0]
      $liveParty[@liveLength] = $liveParty[0]
      $liveParty[0] = $liveParty[1]
      @switchLeader = 0
    end
  end
  def check_hp_out
    if $game_party.actors[0].hp == 0
      if $liveParty.size > 1
        @switchLeader == 1
      else
        @call_GOVER_process = 1
      end
    end
  end
  def all_p_dead
    if @call_GOVER_process == 1
      if $game_switches[GOVER_OR] == false
        $scene = Scene_Gameover.new rescue nil
      else
        $game_switches[GOVER_FLIP] = 1
      end
      @call_GOVER_process = 0
    end
  end
end

Just put that in and press the Q button. If you're not getting an error, try having multiple party members when you push it.

thanks for the help.
 
Where is @liveLength defined?

I think if you add a attr_accessor :liveLength to the top of the class,
it should create the assignment methods automatically.

Or, you just need to initialize it before you use it...??

Be Well
 

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