playMaker

Author Topic: Custom Actions: Is it possible to set UseVariable true for all Array-Elements?  (Read 1362 times)

Deek

  • Full Member
  • ***
  • Posts: 133
For a while now I started creating custom actions that are tailored to my needs, but I can't figure out how to set all Elements of an Array to UseVariable = true (if even possible).
For a single
Code: [Select]
FsmGameObject _go it works with
Code: [Select]
_go = new FsmGameObject() {UseVariable = true}; in Reset(), but how would I do it with an FsmGameObject[] _go while still specifying the default amount (new FsmGameObject[3])?

Probably just my lack of programmatical understanding...
The pictures show the actual and the desired behaviour.

Thanks in advance.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 Can you paste the full Action, I'll see what we can do.

Bye,

 Jean

Deek

  • Full Member
  • ***
  • Posts: 133
The script is in the attachments.
Sidenotes:
I added some functionality (the two FsmBool's) that also utilize the UseVariable = true change and it works on them flawlessly since they are no arrays. In the Screenshots you see 'Test Action' because I copied the code over to a dummy to not mess up my implementations of the original.

What I've already tried (all in the Reset()-function):
1.
Code: [Select]
for (int i = 0; i < NGUISpriteAmount.Length; i++)
{
NGUISpriteAmount[i] = new FsmGameObject() {UseVariable = true};
}
This actually mimics the desired behavior of showing 'None' instead of 'None (GameObject)' but it isn't scalable: When I add another Element it shows the latter (as seen in the Screenshots attached). But I also don't think it is a good idea to cycle through Elements in Reset() let alone create Objects of Objects...

2.
Code: [Select]
foreach(var tmp in NGUISpriteAmount)
{
tmp = new FsmGameObject() {UseVariable = true};
}
This throws the error: "Cannot assign 'tmp' because it is a 'foreach iteration variable'", but I think even if it would work it would probably not be scalable like in the first try.

3. Different variations / combinations of the UseVariable assignment and Array-Initialization:
Code: [Select]
NGUISpriteAmount = new FsmGameObject[3] {UseVariable = true};Throws: "An array initializer of length `3' was expected"
Code: [Select]
NGUISpriteAmount = new FsmGameObject[] {UseVariable = true};Throws: "The name `UseVariable' does not exist in the current context"

If it is not possible to also assign UseVariable = true for every later added element I can live with that, but it would still be neat if there is a way.