playMaker

Author Topic: coroutine in script  (Read 2177 times)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
coroutine in script
« on: June 01, 2016, 10:29:11 AM »
Hi,
i am tying to make some actions to use http://dreamlo.com/ for a online highscore.

and i am trying to convert from this script :

the problem is that i need to use a coroutine

Here is my Script so far :

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
// Action Made By : DjayDino
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using UnityEngine;
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Web")]
[Tooltip("Saves highscore to Dreamlo website")]
public class DreamloAddScore : FsmStateAction
{
[RequiredField]
[Tooltip("Place Private Code from the Dreamlo website")]
public FsmString privateCode;

[RequiredField]
[Tooltip("Place Public Code from the Dreamlo website")]
public FsmString publicCode;

[RequiredField]
[Tooltip("Place Player Name Here. Player Name Must be urlfriendly (if player name exists it will change to the highest score and not add the name a 2nd time)")]
public FsmString PlayerName;

[RequiredField]
[Tooltip("Place Player Score Here")]
public FsmInt PlayerScore;

[Tooltip("Place Player Seconds left, Seconds done or any int value you need (level for example)")]
public FsmInt Secconds;

[Tooltip("Place any String here for example surname or rank (like Sergeant for example)")]
public FsmString text;

public FsmEvent isError;
[Tooltip("Where any errors thrown will be stored. Set this to a variable, or leave it blank.")]

public FsmString errorMessage = "";

private WWW www;

public override void Reset()
{
privateCode = null;
publicCode = null;
PlayerName = null;
PlayerScore = null;
Secconds = null;
errorMessage = "";
}

public override void OnEnter()
{
AddNewHighScore();

Finish();
}


public void AddNewHighScore()
{
if (text != null)
{
if (Secconds == null)
{
Secconds = 0;
}

www = new WWW("http://dreamlo.com/lb/" + privateCode.Value + "/add/" + WWW.EscapeURL(PlayerName.Value) + "/" + PlayerScore.Value + Secconds.Value + WWW.EscapeURL(text.Value));
Debug.Log("Has Text");
}

if (Secconds != null & text == null)
{
www = new WWW("http://dreamlo.com/lb/" + privateCode.Value + "/add/" + WWW.EscapeURL(PlayerName.Value) + "/" + PlayerScore.Value + Secconds.Value);
Debug.Log("Has Secconds");
}

if (text == null & Secconds == null)
{
www = new WWW("http://dreamlo.com/lb/" + privateCode.Value + "/add/" + WWW.EscapeURL(PlayerName.Value) + "/" + PlayerScore.Value);
Debug.Log("No Text No Secconds");
}
}
}
}

I am not using on awake, i only want a single score to be send each time i use the action.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3201
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: coroutine in script
« Reply #1 on: June 01, 2016, 11:43:13 AM »
With 1.8.1 you can use Coroutines in actions.

Example usage:
https://hutonggames.fogbugz.com/default.asp?W1355

This should allow you to convert that script a lot easier.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #2 on: June 01, 2016, 03:48:31 PM »
Hi,
Thx i got it working now and indeed a lot easier :)

Is there a way to show or that this will only work on 1.8.1+ on the EcoSystem and/or when installed on a lower version?

(to jean) i want to have the actions i am making as a bundle, how can i do that or can i send them to you when i finish them?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3201
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: coroutine in script
« Reply #3 on: June 01, 2016, 06:36:00 PM »
Playmaker 1.8.1 adds a PLAYMAKER_1_8_1 Scripting Define Symbol you could use.

Jean may also have methods in the Ecosystem to restrict access to certain Playmaker versions...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #4 on: June 02, 2016, 02:00:43 AM »
Hi,

I need to be able to have a selection list to select  xml/json/pipe and some others
just like you would have to select a variable type.

I think i saw it on a action before but i can't find it anymore

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #5 on: June 02, 2016, 03:52:30 AM »
Also if possible,

It will have an option to choose to sort by name, by seconds or do not sort.
But i would like to to have a sub option then to choose ascending or descending.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3201
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: coroutine in script
« Reply #6 on: June 02, 2016, 07:09:24 AM »
If you define Enums for your selections and declare a public field with that Enum you will get a selection popup. Is that what you're looking for?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #7 on: June 02, 2016, 11:08:05 PM »
Hi,
yes, but i 2 of the 4 selections need a sub selection.
how can i achieve that?

So when i select selection 2 and 4 it would pop up another selection with 2 options to choose from

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3201
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: coroutine in script
« Reply #8 on: June 03, 2016, 07:41:50 AM »
That sounds like you'd need to write a CustomActionEditor.

Or show the sub selections all the time, regardless of the first selection.

For examples of CustomActionEditors check out PlayMaker/Actions/Animator/Editor.

They're pretty easy to write and give you complete control over the UI.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #9 on: June 03, 2016, 10:32:16 AM »
Ok,
Thx i will check that out.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: coroutine in script
« Reply #10 on: June 05, 2016, 11:53:00 PM »
Hi,

 Catching up now after a great Unite :)

 so, where you able to get where you wanted? I am not sure what you mean to ask re distribution? can you rephrase? If you want me to send stuff for review, please do.

 Bye,

 Jean


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #11 on: June 06, 2016, 01:01:54 AM »
Hi,
Yea i noticed to late that it was in amsterdam.
I could not get free anymore from my work :(

I am still working on a few actions, what i want is to have the actions i made into a package on the EcoSystem and not as single actions

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: coroutine in script
« Reply #12 on: June 06, 2016, 01:07:10 AM »
Hi,

 That's cool. you know the procedure to publish packages to the Asset store right?

Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: coroutine in script
« Reply #13 on: June 06, 2016, 01:09:13 AM »
Hi,
No, i have not done that yet.
Thats what i was asking, how to do or if i can send the actions to you.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: coroutine in script
« Reply #14 on: June 07, 2016, 12:23:17 AM »
Hi,

 Ok, send it to me, I'll put in on the Ecosystem and then you'll see how it was done when you pull the rep on your end.

Bye,

 Jean