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.

Conditional Branch (character in 1st spot, 2nd etc.)

I have a common event that has a "Force Action" occur, and it needs to be performed by a specific character. The problem is, the Force Action only lets you choose character spots, (Actor 1 - 4) for the character taking the action, and not the specific character, and that the Conditional Branch doesn't have "If __Insert Character__ is in _Spot_" choice.

So, I'm wondering if anyone knows a script that can be used in the conditional branch that checks if the character is in a specific spot.

Any help would be greatly appreciated, and I hope I explained that well enough. Thanks.
 
$game_party.actors[#].id == #

I can't remember exactly how it's supposed to go into the conditional branch command, but I think that's the right way. The first number is the slot in the group, from 0 - 3. The second number is the actor's id in the database.

edit: Oops, good catch below. Was working with another language earlier this morning that doesn't need two :)
 
It's at the last page of Conditional Branch window. Choose "Script", it's the last option available. Just enter at the box as sandgolem suggests. After completed, your event page may look something like this (doesn't really matter though as long as you do it correctly):

Code:
<> If $game_party.actors[0].id == 1
<>
: End
<>

Note that I use double equal sign (==) instead of single one (=), since for Ruby scripts (and many other programming language), == is the operator of "equality", not "assignment" as usual.

Although... with large party, it doesn't make sense anymore to use conditional branch command, but I can't imagine how we can combine "case" Ruby command with event commands. It may look something like this in Ruby:

Code:
case $game_party.actors[<some_number_here>].id
when 0:
#do something
when 1
#do something
#and so on...
#else (optional)
end

Or something like this if you want to give different acts depending on an actor's slot in Ruby:

Code:
#define a method to find actor's slot first
def actor_slot(actor_id)
for i = 0 ... $game_party.actors.size
return i if $game_party.actors[i].id == actor_id)
end
return -1
end

#now we can use it, shall we?
case actor_slot(1) #for example
when 0
#do something
when 1
#do something
#and so on... until 
else
#our actor is not found!
end

Please don't try these codes as they are estimation (pseudocodes) only and not tested yet.
 

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