playMaker

Author Topic: Something odd with a particular custom action (Random switch.)  (Read 1925 times)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Something's going bonkers... Not sure how to bring this up... But it's with a custom action I've made.

It's the "Random Switch" one... And when I try to select it in the action browser the action browser tab seems to crash (it results in the picture attached.)

Tried it with another custom action I've made, no bugs (I've tried it with the "encode bit flag" and it's partner "decode" action)

FWIW here's the code for the action as it is... I'm trying to reference this to see about updating the encode/decode bitflag actions so that it's not showing "element 0" for each... It's just a cosmetic adjustment but I felt I should reference this since I somehow managed to get the right labelling.)

Code: [Select]
// PlayMaker is (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
//
// This action was created in 2015 by Wesley M. Brown of BadSeedGames for use with the PlayMaker system.

//NOTE: This is beta at this point. It may benefit from additional adjustment or tweaking depending on if this action evolves.

using System.Collections.Generic;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.StateMachine)]
[Tooltip("Randomly calls an event to transition to another state.")]
public class RandomSwitch : FsmStateAction
{
[Tooltip("Declare how many events to choose from.")]
[CompoundArray("Event Switches", "Weight", "Send Event")]
[HasFloatSlider(1, 10)]
public FsmFloat[] weights;
public FsmEvent[] sendEvent;

public override void Reset()
{
sendEvent = new FsmEvent[1];
}

public override void OnEnter()
{
DoRandomEvent();
Finish();
}

void DoRandomEvent()
{
if (sendEvent.Length == 0) return; //If there are no events listed, end this system.

int randomIndex = ActionHelpers.GetRandomWeightedIndex(weights); //Gets a random value with weighted influence.

if (randomIndex != -1)
{
Fsm.Event(sendEvent[randomIndex]); //Fires off the event at the appropriate index that's chosen.
}
return; //Returns to the OnEnter function in case none of the events are determined to have been fired.
}
}
}

No idea what's going on here... I'll continue poking and prodding to see if I can isolate if there's something that's going odd or wrong in another of the custom scripts I've made... But for what this is as things are now this is an issue I've been facing and if you can see what's causing it I'd be very grateful to know what that is so I can fix it (and avoid making that mistake going forward.)

Cheers!

EDIT: I've tested it by removing all my custom scripts from the project... So, that eliminates them... What's left in the project are only the project files, a test level and the ecosystem... I'll test by removing the ecosystem next to see if that's causing it... But I suspect that's not it and it's the action itself that's causing this bug.

EDIT again: Yeah, removing the ecosystem didn't remove this bug... So, I know that's safe (sorry if that sounded like I was doubting but it's part of the troubleshooting process to hopefully isolate what's causing this... And since I'm a coding nooblet this is something I'm not sure of at this point.)
« Last Edit: July 03, 2015, 04:09:34 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Something odd with a particular custom action (Random switch.)
« Reply #1 on: July 03, 2015, 04:17:01 PM »
I think I've been able to isolate what's going on... Or, at least what line of code is causing this...

It's in the "Reset" bit... The exact line is

Code: [Select]
public override void Reset()
{
sendEvent = new FsmEvent[1]; <- This is the line causing the bug.
}

This is in Unity5... I developed this script in Unity4... So, I'm going to test Unity4 to see if this is an issue there as well and I just missed it or something.

EDIT: Yeap, it's ocurring in Unity4 as well... Not sure if I missed it, I'll test to see if it's the same line there as well... I suspect it may be.

EDIT again: Yep, same line in 4 as in 5.

So, I guess if that line is causing issue, what did I do wrong? If you know and can show me what I can do to fix that, I'd be grateful.
« Last Edit: July 03, 2015, 04:19:45 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Something odd with a particular custom action (Random switch.)
« Reply #2 on: July 03, 2015, 04:22:12 PM »
I've replaced the "[1]" with "
  • " and that seems to have cleared it up...


So, it may be that the preview window in the browser may not be parsing the array/table/thing I have set up...

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Something odd with a particular custom action (Random switch.)
« Reply #3 on: July 03, 2015, 04:24:50 PM »
And I think I figured out what caused it... In the reset I told it to set one of the values but there are two values that need to be declared.

Code: [Select]
public override void Reset()
{
weights = new FsmFloat[1];
sendEvent = new FsmEvent[1];
}

That's the new edit which seems to be working (for now.)