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.

Party Slot Conditional branch

I was wondering if it is posible to detect witch slot that a party member is on whether through script or events.

Say if (NAME) is in slot two, do something else.
Maybe it is possible to identify each slot with a script tag and check if a condition is true?
Im not fluent with scripting at all, so it would be very helpful if I had some guidance.

The only event that camee close that I found was 'if (NAME) is in party' which is too vauge for what I need.
 

Atoa

Member

$game_party.actors[Index]

Index = position of character (remember, it starts from 0, so 0 = slot 1, 1 = slot 2...)

Ex.: "if $game_party.actors[0].id == 2" means "if Character ID 2 is in the slot 1...."

$game_party.actors[index].id  >>> returns de ID of Character
$game_party.actors[index].name  >>> returns de name of Character
$game_party.actors[index].hp  >>> returns de HP of Character

Theres more commands but i won't list them all here '-'

you can use it whit de last comand in the conditional branches.
 
OK. those commands can be brought up in an event window by using the script option. right?

Edit: Forget that question. That was obvious.

What id like to ask is how does this act as a conditional branch. When I enter the script it shows as one line.. now the way I understand
if statements they enclose a condition ... but the line doesnt enclose anything..so how do I know that if that condition is met, only one branch will
be activated. or 'else' something else will.

Edit: Ok again forget my question as I did not fully read through your post. Sorry and thank you for your help

Here is a legitimate question. When i run the branch it gives a syntex error. Are you sure that is the exact code?
 
Do you want to use the conditional in the script, or do you want to use the conditional command from the event tabs? If you want to the latter, select add conditional branch, goto the last tab, select script, then put $game_party.actors[INDEX] == "NAME"; where name is the actors name you want, and index the place in the party they should be at(numbering starts from 0). Then just use it like a normal conditional. If you want to use this as a conditional in the little script box, then it should look like this:
  If $game_party.actors[INDEX] == "NAME"
          A
    else
          B
    end

Where A is the code you want to run if its true and B what to do if it not.
Let me know if you have any other questions.
 
Yup. That is exactly the setup I have. I understand the logistics behind it. Im just getting the syntax error now.

I have:
if $game_party.actors[1].id == 1
if $game_party.actors[1].id == 2
if $game_party.actors[1].id == 3

in three baranches
 
If you want to do it by id, then you will have to add attr_reader  :actor_id to the actor class, and use actor_id instead of just id. Also, which method are you using? If the conditional branch command, then you don't want the "if" in front; if the script box, then you do want it. :)
 
hehe. Ill do whatever way works easiest. But both name or id would work.

You will have to elaborate about the 'if' not being present.
I am using a conditional branch with the script option highlighted.

Edit:
... I really shouldn't start asking more questions before testing things.. Thank you. I removed the 'if' and worked fine.
 
If you are using the conditonal branch button, then you only need to put A == B, where A and B are two statements; in other words, $game_party.actors[A].name == "B". The reason being is this, the conditonal branch command checks to see if whatever you've put in is true, in other words you don't feed it a conditonal but a boolean. A == B is evaluated by ruby and returns true if they are the same and false if not. You would put the "if" if you were using the script box because you would need to let ruby know that you want it to use a conditonal. :)
 
Edit: Sorry for double post, just coming back to this thread for answers and forgot I posted last

Here is a problem I am coming accross. When there is only on person in the group and the conditional branch checks
for a name I get a nomeathod error for 'name' nil::nilclass.

Is there a way so that if I have only one person in my party using script so that if it is flase,
it will check the other condition I need?
 
Without screen shots of the event itself, this would be my guess: if you have $game_party.actors[1].name and only one party member, then, since that one actor is indexed by 0, there is no actor 0 and the result is nil. The error arises as you can't check the name of nil. You could fix it with a really large nesting of conditionals, but this would be tedious and laggy. Instead if you can wait a few minutes, I'll edit this with a simpler method of doing things.

*edit
Hit F11 to pull up the script editor and go into Game_Party. Goto the bottom and paste the following method above the last "end"
Code:
def name_chk(a_name, index)
    return false if @actors.size < index
    return true if @actors[index].name == a_name
    return false
end

What this does it checks if there is an actor in the index, if not returns false. Then if there is an actor there with the right name it will return true. Finally, if the actor isn't the right one, you'll get a false. To use this, use the conditional branch button, and under scripts put $game_party.name_chk("NAME", I), with NAME the name and I the index. Also, I don't know if I mentioned it, but the first actor in the party has index 0, not 1. If you are having a different issue than the one I guessed(and this won't alleviate it) or you need something else, let me know. :)
 
My problem is a little differnet than you explained, but your meathod of solving it still works for me.
There is always an actor in slot one.
Im trying to check to see if there is an actor in slot 2 [index 1], and see what the name of that actor is.
If the name matches with a conditional, then another action will take place that does something to that secondary actor.
So your code should work.

Your code should do the trick now, Before I had

Conditional branch($game_party.actors[INDEX] == "NAME1")
   
  do  Conditional branch($game_party.actors[INDEX] == "NAME2")

        do    Conditional branch($game_party.actors[INDEX] == "NAME3")

else

else

else

With your method I should eliminate the need for nesting all the conditional branches.
Ill Edit to see if it works.

Edit: Im getting an error now that says .name is undefined on nil::nilclass
Line: return true if @actors[index].name == a_name
 
That's odd. I just tested it in a new game, no problems. Are you running RMXP or RMVX; if VX, then you would want @members (I think, I don't use VX). Do you have any other scripts installed? (shouldn't really matter though). If you do have XP; make an event, open the script button and put in "p $game_party.actors[0]" (no quotes). Have the event set up to activate when you hit the action button; run the event and let me know if you get the same error about nil, or if you get a bunch of data that pops up. :)
 
Im running rmxp not vx. Im starting to get worried that this may be a problem similar to another ive seen...

Other scripts im running are XAS action RPG, catipillar, and Hackels ALLY AI

Ill try your test and post shortly

Edit: Bunch of data pops up
If it means anything ive been experience problems with the AI and caterpillar system on this map. I dont know how they would be effecting this but, who knows...I know I dont.

Also while I havent had time to formally learn Ruby I do have C++ background and because of the compiler being very un-amviguous, copy and pasting code can be extremely
dangerous because word editors use there own language for formatting that , although looks invisible, destroys your project. I do not know if ruby script suffers in the same way that
C++ does but ive learned that even note pad documents are not safe when being sent over the internet, only internet code is safe to copy/paste. It seems that it is unlikely that this is causing the difficulties at hand but as I stated before I dont know much about this system so I would need someone to verify.
 

Atoa

Member

@CMacDady
you can use an case to make this condition
Code:
case $game_party.actors[INDEX].name
when "NAME 1"
  #add the effect here
when "NAME 2"
  #add the effect here
when "NAME 3"
  #add the effect here
end
The "NAME X" = the name of each character
 
(No relation to your question) I edited my previous post if you want to take a look at it

Oh if your talking about my problem with my other script, to have an ally follow you and attack enimies you need to make an event for them and make that event follow you.
But I had erased the events cause I made a mistake on them and it was just easier to make it again...but I had events calling each characters event names so when I deleted them
things started falling aprat. Soon when I aquired my 2nd party member on the map, an event version of the allly would start following me out of no where but it wouldnt do any of the right actions and I could kill it.

Now as for sending you my data, what is the best method of doing so. Havent really done any file sharing over forums (jsut info sharing).

@Atoa. Thank you for sharing. Im sure there are numerous solutions to the problem that all have there disadvantages and advantages, but the real concern now is all the errors the keep poping up when they shouldnt be. Thx though I will test out your method as well.

Edit: and your email is?
 
Okay, I'm utterly confused. I don't really know anything about XAS, and it's big, so the first thing I did was to take it out of the scripts and see if things worked without it; they did. So, I assumed that it had to be a problem caused by XAS. Unfortunately, I'm not to sure how to set it up and the game won't open as its expecting a bunch of graphics I don't have. So, I scaned through the code, didn't notice anything that would be a problem. In fact, XAS would crash if $game_party.actors was calling the nil class. Nonetheless, I removed all the graphics calls and had the game setup the start party at the title, looking at the data there; it shouldn't get a nil class, and the name method is defined for actor objects. In short, there shouldn't be any problems unless they're burried deep, in which case I don't think will ever route it out since the error messages aren't nice enough to point to anything useful.

Just out of curiousity, what did you put in the conditional branch for name and index, if the index wasn't a specific integer, or was a variable that wan't assigned, or something along these lines is the only thing I can think of that we haven't tried. If this isn't the source of the problem (probably not, just hoping so:)), then I'll try to take a look at it tommorow; my schedules weird, I've been up since this time yesterday. Sorry, I didn't figure anything out, yet...I was looking forward to those pints :)
 

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