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.

Getting my game to recognize which character is in 0 positio

ovan35

Member

Alright I'm currently using rmxp. I was on rpgrevolution and got some help with a character changer.Basically I wanted to be able to cycle through my other party members and have their character graphic appear on the map by simply pressing the shift button.FoeverZero quickly came up with this code and it works fine.

Code:
class Game_Map

  

  SHIFT_BUTTON = Input::A

  # This is the SHIFT button by default.

  

  alias zer0_party_shift_upd update

  def update

    zer0_party_shift_upd

    if Input.trigger?(SHIFT_BUTTON)

      $game_party.actors.push($game_party.actors.shift)

      $game_player.refresh

    end

  end

end

 

Now I wanted a way for the game to recognize which character graphic is currently on screen.The reason is because I want some NPCs to have different things to say to the characters depending on who they are talking to and I'm hoping to be able to have puzzles that can only be solved by using specific character's abilities..(Think like Wild Arms).What I thought of was to use switches in conjuntion with my code.For each character their would be a corresponding switch.The code would look at the actor id in the first position of the party.And whoever's id is in that spot the switch will be cut on for that character.This is the code that I came up with.But when I tried it and just doesn't work.
Code:
 

#What I want this one to do is to recognize which character is currently  

#on the screen and to activate a switch depending on who it is.

class Game_Party

  def whos_who

    #Get the ID of the hero in position 0

    id = @actors[0].id

    #now we check that id and depending on who it is we turn the corresponding

    #switch on

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

    #Tamara

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

    if id == 9

      $game_switch[10] = true

    else

      $game_switch[10] = false

    end

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

      #Shiro

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

    if id == 1

      $game_switch[11] = true

    else

      $game_switch[11] = false

    end

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

      #Rhellik

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

 

        if id == 7

      $game_switch[13] = true

    else

      $game_switch[13] = false

    end

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

      #Demetria

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

 

    if id == 2

      $game_switch[12] = true

    else

      $game_switch[12] = false

    end

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

      #Alicia

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

 

    if id == 6

      $game_switch[14] = true

    else

      $game_switch[14] = false

    end

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

      #Felicia

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

 

    if id == 5

      $game_switch[15] = true

    else

      $game_switch[15] = false

    end

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

      #Caleb

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

 

    if id == 4

      $game_switch[16] = true

    else

      $game_switch[16] = false

    end

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

      #Mina

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

 

    if id == 3

      $game_switch[17] = true

    else

      $game_switch[17] = false

    end

 

  end #for my def

end #for my class
No errors occur when the game starts.But none of the switches are ever activated.I can't figure out why.
 
Well, for once I'm glad to see that hbgames.org is not the only place full of messy scripters...

Let's see... first of all, the script you posted first (doesn't seem to be all of it, as shift isn't a method defined by default, if I'm not mistaken) contains what I like to refer to as redundant use of exclusive value containers... or in short, a bullshit constant. Replace it with this and rejoice because of the vast performance and logic improvement:
[rgss]class Game_Map
  alias player_sprite_shift_update update
  def update
    player_sprite_shift_update
    if Input.trigger?(Input::A) # This is the SHIFT button by default.
      $game_party.actors.push($game_party.actors.shift)
      $game_player.refresh
    end
  end
end
[/rgss]

Second, your problem can be much simplier addressed, without the need for ANY additional switches, variables or even scripts. All you need is a script line in your conditional (event command conditional, that is) that can look somewhat like this:

Code:
if (Script: $game_party.actors[0].graphic == $data_actors[0].graphic)

  Message: "Oh hey, I'm apparently talking to Database Actor #1!"

elsif (Script: $game_party.actors[0].graphic == $data_actors[1].graphic)

  Message: "Looks like I'm talking to Database Actor #2..."

end

Note that this suggestion is based on the assumption that you replace the currently first actor in the party with another in the script above... it might be me being stupid and not knowing the shift method, but yeah... even if that's not the way it's handled, there's an easy way to define those conditions in just event command conditionals, aka no reason to break your head over a script there.


A much fancier way would be to do all of this with an additional variable within $game_player that could be called @active_actor, which is used for sprite drawing and checking alike, as you could simply use if ($game_party.active_actor == 0) then, for example, and also need nothing else than cycle through numbers for changing the graphic; therefore you'll have a much easier setup. You'd also gain a lot of compatibility with other scripts, as you're not changing the actual party order, but just set an additional variable that handles just what you need: Visuals and message handling.


All that being said, this is an actually nice idea... and I don't say that all that often. Might evolve into a pretty fancy system if you fine-tune it and use it well.
 

ovan35

Member

Code:
if (Script: $game_party.actors[0].graphic == $data_actors[0].graphic)

  Message: "Oh hey, I'm apparently talking to Database Actor #1!"

elsif (Script: $game_party.actors[0].graphic == $data_actors[1].graphic)

  Message: "Looks like I'm talking to Database Actor #2..."

end

 

I guess I should have said I'm new at scripting.But I assume you're talking about the script box on the conditional branch section.The second question is you had Script: What is this part about?The rest of it I understand.
 
Just think of the code tag (without colored code highlighting) as an event entry, so the first, third and fifth line is aconditional branches, the second and fourth line a message. For the first line, you'd put $game_party.actors[0].graphic == $data_actors[0].graphic in the Script: field of your conditional.
Also, the : is meant to by a : really... no idea what went wrong there.
 

ovan35

Member

BlueScope":2hb5i29x said:
Just think of the code tag (without colored code highlighting) as an event entry, so the first, third and fifth line is aconditional branches, the second and fourth line a message. For the first line, you'd put $game_party.actors[0].graphic == $data_actors[0].graphic in the Script: field of your conditional.
Also, the : is meant to by a : really... no idea what went wrong there.

Thank you very much for your help..It was actually even easier than you suggested.This is the code I put in the script section
$game_party.actors[0].id == 9

The number 9 is the actor id of my main character..I could put similar code for any of the others.

first of all, the script you posted first (doesn't seem to be all of it, as shift isn't a method defined by default, if I'm not mistaken)

Yeah I wasn't too sure about that part either but it works just the same.No other code was needed on the code he gave me and I posted it just as it was originally.I was honestly surprised with how little code it actually took.Definitely got to learn more about scripting.Thanks again!
 
ovan35":362rnvc6 said:
Thank you very much for your help..It was actually even easier than you suggested.This is the code I put in the script section
$game_party.actors[0].id == 9
Yeah, that was kinda stupid of me... obviously, what you did is the easier way >>
 

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