playMaker

Author Topic: custom itween action error  (Read 1451 times)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
custom itween action error
« on: October 17, 2014, 09:23:01 AM »
hi, i am making my own itween action but i get an error and can't find the solution (yet)

the action needs to change from int "a" to int "b" and store that result each frame.
i dont get errors on the script but when i play i get this error :
Quote
iTween Error: ValueTo() only works with interpolating Vector3s, Vector2s, floats, ints, Rects and Colors!
UnityEngine.Debug:LogError(Object)

this is my script :

Code: [Select]
{
[ActionCategory("iTween")]
[Tooltip("Changing Int value 1 to value 2")]
public class iTweenIntValueTo: iTweenFsmAction
{
[RequiredField]
public FsmOwnerDefault gameObject;

[Tooltip("iTween ID. If set you can use iTween Stop action to stop it by its id.")]
public FsmString id;

[RequiredField]
[Tooltip("IntValue from.")]
public FsmInt Int1;
[Tooltip("IntValue to.")]
public FsmInt Int2;
[Tooltip("IntValue to.")]
public FsmInt newValue;
[Tooltip("The time in seconds the animation will take to complete.")]
[UIHint(UIHint.Variable)]
public FsmInt storeResult;
[Tooltip("The time in seconds the animation will take to complete.")]
public FsmFloat time;
[Tooltip("The time in seconds the animation will wait before beginning.")]
public FsmFloat delay;
[Tooltip("Can be used instead of time to allow animation based on speed. When you define speed the time variable is ignored.")]
public FsmFloat speed;
[Tooltip("The shape of the easing curve applied to the animation.")]
public iTween.EaseType easeType = iTween.EaseType.linear;


public override void Reset()
{
base.Reset();
id = new FsmString{UseVariable = true};
time = 1f;
delay = 0f;
Int1 = new FsmInt { UseVariable = true };
Int2 = new FsmInt { UseVariable = true };
storeResult = new FsmInt { UseVariable = true };
speed = new FsmFloat { UseVariable = true };
}

public override void OnEnter()
{
base.OnEnteriTween(gameObject);
// if(loopType != iTween.LoopType.none) base.IsLoop(true);
DoiTween();
}

public override void OnExit(){
base.OnExitiTween(gameObject);
}


public void DoiTween()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
// init position
itweenType = "value";
iTween.ValueTo(go, iTween.Hash(
"from", Int1.Value,
"to", Int2.Value,
"name", id.IsNone ? "" : id.Value,
speed.IsNone ? "time" : "speed", speed.IsNone ? time.IsNone ? 1f : time.Value : speed.Value,
"delay", delay.IsNone ? 0f : delay.Value,
"easetype", easeType,
"onupdate", "tweenOnUpdateCallBack",
"onupdatetarget", go,
"oncompletetarget", go,
"oncomplete", "iTweenOnComplete",
"oncompleteparams", itweenID,
"onstart", "iTweenOnStart",
"onstartparams", itweenID,
"ignoretimescale", realTime.IsNone ? false : realTime.Value
));
}

public void tweenOnUpdateCallBack()
{
// storeResult.Value = 50;
Debug.Log ("test");
storeResult.Value = newValue.Value;
}
}

}

i am not a scripting expert and copy paste most of it :)
does anyone have an idea why i get the error?

edit : removed looptype because it can not be used in valueto.
but problems is still there.

edit 2 : added .Value  int1 and others
error is gone but not getting result

edit 3 : added public but did not change anything
« Last Edit: October 28, 2014, 07:56:51 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: custom itween action error
« Reply #1 on: October 18, 2014, 07:27:42 PM »
this is the script i made which i want to change into an playmaker action :

Code: [Select]
using UnityEngine;
using System.Collections;

public class ValueTo : MonoBehaviour {
public int int1 = 0;
public int int2 = 100;
public GUIText scoreDisplay;

void OnMouseDown(){
//go from value 1 to value 2
iTween.ValueTo(gameObject,iTween.Hash("from",int1,"to",int2,"time",6,"onUpdate","UpdateScoreDisplay","easetype","easeOutBounce"));

}

void OnMouseUp(){
}

void UpdateScoreDisplay(int newScore){
scoreDisplay.text = "Score: " + newScore.ToString();
}
}

and this works

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: custom itween action error
« Reply #2 on: October 20, 2014, 04:00:09 AM »
Hi,

 You are overthinking this:) you have everything already there for this.

Use the action "HOTween int" and you are done for the int tweening, then convert the int as a string, and inject that in your guitexture component.

 creating custom actions using hotween requires some advanced skills, and indeed simply inspire from "HOTween int" if you want to make your own, that's your best start.

 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: custom itween action error
« Reply #3 on: October 20, 2014, 06:15:13 AM »
i do not have that action...
 and saw now that HOTween is another asset.

I am using the standard iTween which comes with playmaker.
HOTween looks nice and will test it for my next project.

for now i would like to get this action to work
(or at least know what i'm doing wrong)

do you have an idea whats wrong with it?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: custom itween action error
« Reply #4 on: October 20, 2014, 08:14:52 PM »
You have to use int1.Value instead of int1 to pass the int to iTween.

So instead of:
Code: [Select]
iTween.ValueTo(go, iTween.Hash(
"from", Int1,
"to", Int2,

Do this:
Code: [Select]
iTween.ValueTo(go, iTween.Hash(
"from", Int1.Value,
"to", Int2.Value,

Not tested here, so there may be other issues, but that's the one that jumped out at me reading the code...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: custom itween action error
« Reply #5 on: October 21, 2014, 06:02:01 AM »
Yes, thank u that got rid of the error,
i should have seen that, i think i was searching to deep and overlooked that :)

but i am not getting any result
everything else seems to work (time, delay, id)

i tried this for testing but did not get result either :

Code: [Select]
void tweenOnUpdateCallBack()
{
Debug.Log ("test");
}

so i guess it is not calling tweenOnUpdateCallBack.

i also tried with changing tweenOnUpdateCallBack to OnUpdate (on both hash and void)

also tried adding onupdatetarget hash but no result.

so i guess i need to let onupdate call back to this script somehow.

any idea?

and thx for the help

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: custom itween action error
« Reply #6 on: October 24, 2014, 08:37:26 AM »
Bump, anyone any idea why its not calling back?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: custom itween action error
« Reply #7 on: October 27, 2014, 10:39:21 PM »
Hi,

 you get no errors or warning in the console?

 What if you make the method public? I think it could be the problem.

 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: custom itween action error
« Reply #8 on: October 28, 2014, 08:11:10 AM »
Hi,

no i get no errors but also no debug log in the update part

i have added public but it did not change anything.
i edited my script on the 1st post so you can see what i did.

it must have something to do  with the onupdate hash i think,