Android Question multiclass & sub referencing

sorex

Expert
Licensed User
Longtime User
Hello,

While I'm rewriting some games to meet Google's requirements I thought about restructuring things a bit with the creation of extra classes.

While my old code was like

[main activity]
\game init/start
\ad init & handler sub
\in-app purchases manager init & handler subs
[game class]
[tween class]

I now tried to go for

[main activity]
\game init/start
\ad init
\in-app purchases init
[game class]
[tween class]
[consent+interstitial class]
[in-app purchases class]

while for example it's easy to set values from in the in-app class like

B4X:
main.remove_ads

it's more difficult to use a sub like

B4X:
main.purchased_noAds

as it simply doesn't show up in the intellisense.

B4X:
CallSum(main,"purchased_noAds")

is a solution but then I keep having in-app code in the main activity.

B4X:
Sub Purchased_NoAds
    game.remove_ads 'remove ad remover/restore buttons from the game menu
    remove_Ads=True 'used in the ads subs to bypass things
End Sub

----------

I also tried the method below as sub inside the in-app class which would've been perfect if it worked

B4X:
Sub Purchased_NoAds
main.game.remove_ads
main.remove_Ads=True
End Sub

but that required me to move the dim game to Process Globals but then the log showed an error that it wasn't allowed due to some referencing or something?


Is there a more ideal way to do this that I'm not aware of to keep things really seperate and not just 50/50?
 

sorex

Expert
Licensed User
Longtime User
the error in the log is "Cannot access activity object from sub Process_Globals"
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It is not clear to me what you wrote.

main.purchased_noAds
as it simply doesn't show up in the intellisense.
Should not this code be like this?
B4X:
main.purchased.noAds
where "purchased" is an instance of your class and "noAds" is a method/property?

However, I feel that you need to pass the callback to a class, that is, the module "on which the class will act", "its parent".

If, by chance, I was not the only one who did not understand the problem well, maybe you could try to explain differently.

But I am sure that others will have understood and will help you, so I go for a "walk" .
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
no, NOW there's a sub in main called "purchased_noAds".

I would like to move that to the in-app purchases class so that everything related is in the same module.

So the last piece of code upthere would be making most sense but it's not possible that way.

It seems that from a class I can only access the Main variables and not subs. that's what I meant with the line you quoted.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
small correction to the last line in the previous post...

I can seem to access class B subs from in class A.

It seems that only the game class is the culprit because of the activity reference or views creation it has?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…