Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: blackant on May 17, 2019, 06:55:33 AM

Title: corresponding Array lenght based on existing array
Post by: blackant on May 17, 2019, 06:55:33 AM
Hello,

for my game in need to have multiple arrays, and it pose me a problem because of this:


but the thing is that it doesn't really work and i don't know why.

The first action get the length, set to 1
the second action and range to 0
the third action add range to 1

so there is a difference from one action to the other and no error displayed anywhere, so it's a problem of logic for me…

can someone help ?
Title: Re: corresponding Array lenght based on existing array
Post by: blackant on May 17, 2019, 06:58:45 AM
here is the modified code:

Code: [Select]
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Array)]
[Tooltip("Add values to an array.")]
public class ArrayAddRange : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The Array Variable to use.")]
public FsmArray array;

public FsmInt RangeLength;

[RequiredField]
[MatchElementType("array")]
[Tooltip("The variables to add.")]
public FsmVar[] variables;

public override void Reset()
{
array = null;
RangeLength = 2;
variables = new FsmVar[RangeLength.Value];
}

public override void OnEnter()
{
DoAddRange();

Finish();
}

private void DoAddRange()
{
int count = variables.Length;

if (count>0)
{
array.Resize(array.Length+count);

foreach(FsmVar _var in variables)
{
                    _var.UpdateValue();
array.Set(array.Length-count,_var.GetValue());
count--;
}
}

}


}
}
Title: Re: corresponding Array lenght based on existing array
Post by: blackant on May 17, 2019, 07:21:30 AM
well… i'll use Array.Resize instead
Title: Re: corresponding Array lenght based on existing array
Post by: blackant on May 17, 2019, 07:37:56 AM
i fund my problem was that i had let an additional add array somewhere else... ::)