#How do I activate the twist when the rewarded ad is watched?

1 messages · Page 1 of 1 (latest)

hollow flower
#

Hello, I have two scripts here: one activates a rewarded ad and the other deals with all my gameplay.

I've tried a lot and I'm not sure if it's a small stupid error but I can't figure out how to activate the 'twist' in the field script (basically a powerup) AFTER the ad is watched.

Anyone, please help me here, I know its probably a small issue I just haven't picked up on yet so I need a fresh perspective from another developer. Here are the scripts:

Field script(where all the gameplay stuff is and the twist im trying to call is here):

#

And loadRewarded script (where im trying to call the twist/powerup after the ad is watched:

fiery stratus
#

!code

shell geyserBOT
hollow flower
#

Would appreciate any help on this

fiery stratus
#

I suspect your problem is here

GetTwists().OrderBy(_ => Random.value).Take(3).ToList().ForEach(t =>
        {
            AddLettersTo(t);
            var twist = Instantiate(twistPanelPrefab, twistHolder);
            twist.Setup(t);
            twist.button.onClick.AddListener(() =>
            {
                ApplyTwist(t);
                twist.button.onClick.RemoveAllListeners();
            });
        });

lambda completion

hollow flower
fiery stratus
#
var t1 = t;
twist.button.onClick.AddListener(() =>
            {
                ApplyTwist(t1);
                twist.button.onClick.RemoveAllListeners();
            });

Not sure if that will solve your problem as you don't actually explain what you problem is

hollow flower
#

The problem is that the twist doesn't load after closing the ad. Basically the loadRewarded script is meant to activate a twist once the ad has been watched from the field script. But as of now, the ad is initialised and can be closed but doesnt load any twist.
What Im trying to do is load the twist from the 'Field' script once the ad has been watched. Hope that does make sense (I am a beginner with the whole ad stuff, so bear with me)

fiery stratus
#

you've got debugging in your loadRewarded script (which, for some reason you have not shared with us) and no debugging in your Field script (which I find rather odd)

hollow flower
#

This is the loadRewarded script: https://gdl.space/axubebobew.cs
I asked someone else to fix up the loadRewarded and they did some debugging but it didnt work so I guess they never bothered with the Field script.

#

If there is some part of the field script you dont understand lmk, i can try explain it for you

fiery stratus
#

I'm reading the script but without the console log how can I know which paths are taken?

#

I can read the code but without your data it's impossible to know what it is doing. That is why you add logging

hollow flower
#

Ok, what do you mean by data though? Not sure what else do you need to know

#

There are no errors in the console if thats what you mean

fiery stratus
#

I'm not talking about errors, I'm talking about your print statements

#

how can I know which path is taken in the code without that information?

hollow flower
#

like these?

fiery stratus
#

yes, now why have you not added the same level of logging in the Field script?

hollow flower
#

well, i didnt think it mattered so im sorry about that, but the DoTwist function definately does work, the Twist does load when 10 moves are made in the 'Field' script as you can see here:https://gdl.space/poburiqiva.cs but the twist doesnt load after the ad is watched from the loadRewarded script.

fiery stratus
#

like this

if (move == 0 || move % 10 != 0)
        {
            hand.SetState(true);
            yield break;
        }

What is the value of move ?

hollow flower
#

in particular here:
private IEnumerator DoTwist()
{
if (move == 0 || move % 10 != 0)
{
hand.SetState(true);
yield break;
}

#

Yes, if the value of move is == 10 it will call the dotwist function

#

The script adds to the move function whenever they place a card

fiery stratus
#

I can read the code, I know what it does but come on this is debugging 101.
when you start the coroutine from loadRewarded is the Coroutine started? What is the value of move at that point?

#

Really you should be using the VS debugger to step through your code and finding out what it is doing

hollow flower
#

Sorry about that, will make sure to debug on all scriptsgoing forward
The loadRewarded script is initialised on start so the value of move would be 0
About the Coroutine, The coroutine field.DoTwist() is started in the Update() method of the loadRewarded script.
This happens when adViewed is true, which is set to true in the OnUnityAdsShowComplete method when a rewarded ad is successfully completed.

#

Also, if you need any other surrounding scripts like the Hand script lmk, i can send them all

fiery stratus
#

loadRewarded does not have an update method
the coroutine is started in OnUnityAdsShowComplete

#

Did you actually write this code?

hollow flower
#

Oops my bad, the coroutine is here:
field.StartCoroutine(field.DoTwist());
in OnUnityAdsShowComplete as you said

#

No, that's why I need help with it. As you can see I'm not very proficient with programming in general.

fiery stratus
#

Best advice I can give you.
Fill the field script with Debig.Log statements (and include data not just messages) and come back when you have more sensible information to share

hollow flower
#

Closing this thread as the issue has been solved on unity forums.

#

Didnt need to even give them extra information, they solved the issue without debug statements.