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.

Actor/Variable Script

Aerif

Member

I'd like to request a script that constantly updates a set of variables to match with the position of a party member.

Eg.

Say, Aluxes is the first actor in the party, variable one would be set to 1
Hilda is not presently in the party, variable eight would be set to 0

And so on...

I'd like this script to be easy to edit so that more positions can be recorded if the number of actors increases.
 
1.post this in a new page above main.
Code:
class Partypos
  #---------------------------------------#
  # first, create the array with:         #
  # Partypos.make ()  (inside an event)   #
  # to find the position of an actor      #
  # use $party_pos[id]                    #
  #---------------------------------------#
  def initialize
    @data = []
    @data[0] = 0
    update
  end
  
  def update
    party= $game_party.actors
    for i in 0...party.size
      id= party[i].id
      @data[id]= i+1
    end
  end
  
  def [](actor_id)
    update
    if @data[actor_id] == nil
      #no such actor in party
      return 0
    end
    return @data[actor_id]
  end
  
  def self.make
    $party_pos = Partypos.new
  end
  
end
2.make an event with a script command:
Partypos.make

3. now you can use $party_pos[id] to get the position of the actor.(id is actor's id)
ie, the script command:
Code:
$game_variables[1] = $party_pos[1]

will save the position of Aluxes to variable number 001.

To do it like you asked, I would have to update the variables all the time, causing lag.
 

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