• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ Have an instance deactivated at room start and activate on left press

Stratos.la

Member
As the title goes i want to have an instance deactivated on room start and when clicking on it activate it, run its left pressed event and then deactivate it again! Actually i want to have two rewarded ads in the same room but the way i have set things up once the rewarded is fired both "rewards" are given by each press. So its a bought asset and the person who made it told me
Make a new object with same async social event. A instance of that object should exists only when you wants the reward from the ad
and yea short story short i didnt get too much help from that and i didnt feel like they wanted to help so i thought i would ask here of a way to do that or well if my question here is true how i would go about doing that! Thank you!
 

Nidoking

Member
Deactivated instances won't run any events. You need an active instance if you want to perform events. But why are you so dead set on deactivating this instance? Why don't you just make a is_active variable and have the various events only activate if it's true? Make your own custom deactivation that still leaves them "active" in Game Maker terms, but makes them only do stuff when you want them to?
 

Stratos.la

Member
hey thanks for the reply! well im not entirely sure how to do that! assuming its any different with async social . i tried doing a switch statement inside the async , placed two instances on the room and set them up for the switch but still the same
 

Tornado

Member
I don't know which ads extension you use or how it exactly works, but normally you just need one persistent objects (for example (obj_ads_controller) which is serving your ads for the entire application.
It doesn't matter wich ad button you press the same social event in your obj_ads_controller will be fired. I also wonder why you need 2 rewarded video buttons, when you can have one rewarded video loaded at a time.
Wehnn button is pressed you can disable it for a while and when the next rewarded video is loaded (or or your delay timer is up) then you can enable it again.
Or if you really need 2 buttons (for any reason), you can disable/enable them alternately.
 

Stratos.la

Member
well it does have one admob object that load the id and ads and then it has dofferent objects acting as buttons (for rewarded , interstitial banner) each of them have their own left pressed event that sure enough calls the coresponding ad if loaded. the objAdmob is persistent and in the social async it has the onrewarded case which when complete i have it set to give the reward.

GML:
case "onRewarded":
        switch(ad)
        {
            case 0:{   
            show_message_async("100 gold!! Yay!")
            rewarded_viewed = true;
            global.gold += 100
            Admob_RewardedVideoAd_Load(true,true)
            break
            }
            case 1:{   
            show_message_async("10 Skill Points!! Yay!")
            rewarded_viewed = true;
            global.skp += 10
            Admob_RewardedVideoAd_Load(true,true)
            break
            }
        }
and i made a second switch statement inside it and edited the creation code of the buttons but still nothing! i never really used rewarded ads before so im having trouble undertstanding it
 

Tornado

Member
You didn't mention interstitial in your first posting. You said you have two buttons for rewarded video. But ok.
What do you mean by "nothing"?
It is not clear to me which problem you want to solve:
1) some problem with the buttons
2) or some problem with ads

If you have problems with ads, which problem exactly is it?
 

Stratos.la

Member
the ways its setup if i choose say the reward for gold after the rewarded has finished i get both rewards. i have two buttons. one for gold and one for skill points. thats my problem! that the reward call gives me both rewards instead of the one the player pressed on!
 

Tornado

Member
Ok, then you have a problem definetly in your switch...case...or "onRewarded" is fired two times.
What the constants 0 and 1 represent in your case 0 and case 1?

Try to remove unnecessary brackets from your cases and use ";" on every line, like this:
GML:
switch(ad)
{
    case 0:
        show_message_async("100 gold!! Yay!");
        rewarded_viewed = true;
        global.gold += 100;
        Admob_RewardedVideoAd_Load(true,true);
        break;
    case 1:
        show_message_async("10 Skill Points!! Yay!");
        rewarded_viewed = true;
        global.skp += 10;
        Admob_RewardedVideoAd_Load(true,true);
        break;
}
What kind of value is the variable ad holding?
Ads interface can fire several events on some occasions, be sure that case 0 and case 1 are the correct ones.
I would say you get 2 asynch calls with both ad=0 and ad=1.
Check Ads documentation again.
 
Last edited:
Top