Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Help with the case-system

Author
Message
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 14th Sep 2015 22:53
Hi again everybody I am truly thankful for all the help I have recieved on this forum! With your help I have learned things I never thought I would.

So to the question : I have made a case-select loop to cycle between tabs in an app I am currently making. The problem is, that while one of the cases (I have 1 function for each case) works, the other one simply don't "respond".

What I want to do, is just that if a button is pressed, you go back to the main screen. I hide and show sprites for the different menus in the different functions.

This is my mainloop:

This should be OK, right?

And here are my "cases", as functions:


So while "case 2", profile, works fine(it actually return to main menu if I press the mouse, so not working perfectly), anything i try to do in "case 3" dont respond. Have i synced it wrong?

I am sorry if this was very long, but I truly appreciate all help I get!
Thank you so much, in advance.

Just started - Much to learn
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 14th Sep 2015 23:53
It appears it should be calling the right case.
I would make sure you are actually clicking the Friends Button.
I have had a few issues with GetSpriteHit where it returns a random ImageID# could just be from lack of experience in the area.

For testing purposes you could start by loading a Virtual Button off to the side and just change

if GetSpriteHittest(but_friends,GetPointerX(), GetPointerY())

to

If GetGetVirtualButtonPressed(1)

That's just where I would start, Sorry as I'm not much help

Here is an example of another way of doing Menus/Game Playing/ Game Over / Title Screens etc...


Example is provided by Funnell7

^ this is how I structure all of my games now.

http://forum.thegamecreators.com/?m=forum_view&t=213678&b=41

Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 15th Sep 2015 06:45 Edited at: 15th Sep 2015 07:34
What are the equal signs for in the prof() and friends() functions????

function prof() =

function friends() =

Try removing those and see what happens.

Also, check for typos in that friend button ID "but_friends"


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 20th Sep 2015 01:41
Thank you for the answers!

Conjured Entertainment: Those have no meaning, and I have removed them, but still no go, it's not changing anything.

Crazy Programmer: Yes, in my other thread about structuring of apps and games, you gave me the same answer, and this is mostly how i structure it, if I showed you the entire code, it would be by that structure TY very much for that

But still, a week has passed and I can't seem to get this right =( I know that the right sprite is selected =/

Just started - Much to learn
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 20th Sep 2015 03:11
I don't use 'Select' myself, but have you ensured 'progcase' has been declared globally? That's the only thing I can think of...

Using AppGameKit V2 Tier 1
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 20th Sep 2015 23:38
Yes, as "global progcase = 9"
is that right?

Still no solution, I have tried almost anything
Can't really see where I go wrong

Just started - Much to learn
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 20th Sep 2015 23:46
Would it be helpful if I gave you the whole code? Maybe this is a bug in AGK2?

Just started - Much to learn
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 20th Sep 2015 23:49 Edited at: 21st Sep 2015 00:40
Yes it would... I'd be more than happy to take a look...

Edit: Just had another thought. Are any of your buttons overlapping? If so, I'm pretty sure GetSpriteHit() will still register invisible sprites. Therefore if your 'Friends' button is under (based on depth) another invisible Sprite then it will not detect the hit... Honestly, I wouldn't even bother with the hide/unhide approach, I'd just create and destroy each time - a lot cleaner in my opinion and seeing as AppGameKit is so quick at handling Sprite creation, it really isn't an issue doing this on the fly...

Using AppGameKit V2 Tier 1
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 22nd Sep 2015 23:47
That's so kind Funnell7!

To answer your question, no I don't think any of the buttons are overlapping. And I have been a little back and forth between hiding and deleting sprites - if what you say is true, I agree with deleting sprites beeing cleaner as long as it is not too taxing on the cpu.

So, here goes:



Just started - Much to learn
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 23rd Sep 2015 00:12 Edited at: 23rd Sep 2015 00:14
In the function prof() there's a bit of code to detect the pointer being pressed which changes the variable progcase but there's nothing in the friends() function to detect the pointer being pressed or to change the value of progcase.

That would mean that if the player chooses to go to the profile menu there would be no way of getting out of it.

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 23rd Sep 2015 00:37
I know, but even if I delete that piece of code, I STILL go back to main menu if I press a button/click the mouse

Just started - Much to learn
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 23rd Sep 2015 01:04 Edited at: 23rd Sep 2015 01:05
Yes, I see what you mean.

It because you have:

if GetPointerPressed() = 1
progcase = 1
endif

Right at the start of the do loop which will always go to the main menu. Because of the way the program is structured the code always see this if statement so progcase can always be set to 1 no matter what function you're currently in.

If I've understood this correctly, one way to solve this is to take the offending if statement at the start of the do loop and put it into the default case:



The default case then becomes a kind of "press start to begin".

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 24th Sep 2015 23:40
Wow, thank you! That should be the main problem there, but I tried it, and it certainly took care of the problem with returning to the main menu in the profile-page, but I still can't make an if-loop in the friends-case. I can use the print-command etc. but if-loops dont work it seems?

Can it be because of the elseif-command that leads to the case?

Just started - Much to learn
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 25th Sep 2015 02:27
It depends what you mean by "if-loops dont work it seems".

The if statements are working but the way you've structured your code may mean that it's not behaving as you were expecting. I'm not saying that you're basic code structure is wrong, more that you're not fully understanding why your code behaves in the way it does.

Post some code and say what you were expecting versus what actually happened and I (or someone else) will have a chance of understanding the issue a bit more.

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Danishly
8
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 29th Sep 2015 21:56
Ok, let's try again

So here's my code:



So, back to the problem. I use a case-system where i determine the case by which sprite is clicked. Bear in mind, this is a sort of interface/menu I am making now. So if you click on the sprite friends, you go to the friends-screen etc.
By now, every case is only a function. So in the "main menu", if you click on the sprite "but_friends" (but_ = button), you go the the "friends-tab". And here comes my problem : I can't get an if function to work inside that function (friends())
Just started - Much to learn
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 29th Sep 2015 22:42 Edited at: 29th Sep 2015 22:44
Just for grins...Try this



Maybe it will work maybe it wont I couldn't test it
Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 1st Oct 2015 21:28 Edited at: 1st Oct 2015 21:30
Rather than go round in circles, I've come up with a simple example of a menu system that has a main menu then a single layer of sub-menus.



This example uses text instead of sprites and I would not advocate using such a long winded way of creating the various menus. I'd normally use multi-dimension arrays to make it easier to cycle through the various buttons but I thought this would be easier to follow and seemed more in keeping with the way you're already doing things. At this stage I thought it'd be more important to understand the logic.

I did try Crazy's code but it didn't work and, yes, I really did create this example whilst out having a bacon and cheese burger.
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB

Login to post a reply

Server time is: 2024-04-26 02:40:32
Your offset time is: 2024-04-26 02:40:32