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.

AppGameKit Studio Chat / [SOLVED] Decrementing For Loop

Author
Message
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 11th Jan 2020 09:06
Hello forum,

I want to detect number by number if it's available by decrementing. For example, I have 6 as number and I want to detect step by step in decrementing way, if the number below 6 or 5 or 4 or 3 (and so on), is available. Here is my code. Thank you in advance!

www.alexmatei.com

The author of this post has marked a post as an answer.

Go to answer

chafari
Valued Member
17
Years of Service
Recently Online
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Jan 2020 10:38
Hi mate ....try this



I'm not a grumpy grandpa
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Jan 2020 10:40
do you mean ?
for dtctsltseqippd = 6 to currentweaponslot-1 step -1
MerryChristmas Everyone
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 11th Jan 2020 12:11
Hello guys, nice to see you both!

I tried both of the commands, doesn't matter where currentweaponslot is, it jumps straight to 6 when initializing the code
www.alexmatei.com
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 11th Jan 2020 12:20
I don't know if I forgot to mention this, but I need the coundown to start from where currentweaponslot is
www.alexmatei.com
chafari
Valued Member
17
Years of Service
Recently Online
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Jan 2020 14:41 Edited at: 11th Jan 2020 14:42
In that case , you don't need a for/ next....you had better to put a variable and just trigger the weapon value by distance or by collision....

If gun dist < 10 then weapon=6
I'm not a grumpy grandpa
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 11th Jan 2020 14:47 Edited at: 11th Jan 2020 14:47
It's for selecting a weapon by mouse scroll. Currentweaponslot is the current weapon that is equipped and visible on screen.

Edit: The currentweaponslot must be replaced with any number free downwards, decrementing (if any number is available)
www.alexmatei.com
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Jan 2020 14:56
oh I see now the problem is sometimes currentweapon might be 6 and sometimes 1 so the step value would
need to be 1 or maybe -1 so a loop like that cant be used ide use a while loop and precondition it with currentweapon
and when its less than one then make it 6 and if greater than 6 make it one
MerryChristmas Everyone
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 11th Jan 2020 15:01 Edited at: 11th Jan 2020 15:04
infact yes, the problem was that I should had not added -1 to step, but just 1...

EDIT: The code is like this now:



Second Edit: Now, if I make a weapon unavailable so, the number 2, let's say, how can I make it skip directly to 1? Got any idea? Thank you so much
www.alexmatei.com
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 12th Jan 2020 10:16
Sorry for bumping. Any idea? Thank you very much and sorry again!
www.alexmatei.com
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 12th Jan 2020 11:09
Hi Scraggle,

Don't know if the diagram attached helps, so, I will explain: When the user scrolls up and down (mouse scroll wheel), I need to detect incremently and decremently (depending on the scroll if it's up or down), if a variable from 1 to 6 is available to work with. The availabilty of it is determined by an array variable named slotisequipped. If slotisequipped is 0, then the array position let's say, the program picked the number 3... if 3 is unavailable then array[3] is not available so we will move on to 4 or 2. Imagine the weapon scrolling in games.
www.alexmatei.com

Attachments

Login to view attachments
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Jan 2020 11:51 Edited at: 12th Jan 2020 12:11
This post has been marked by the post author as the answer.
How's this?
It uses the arrow keys instead of mouse wheel but you can easily change that.


It's a full 'project' to test the code but the bit you've asked for is the SelectWeaponSlot() function
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 12th Jan 2020 12:12
Nice, Scraggle! Thank you!

Just as a learning curve, from what I made there, from my code, is that a legit way to do it, or there is one specific way like yours?
www.alexmatei.com
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Jan 2020 12:14
Quote: " is that a legit way to do it, or there is one specific way like yours"

There are always many ways to do everything. If what you have works then it works.
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 12th Jan 2020 12:28
Correct! Thank you again!
www.alexmatei.com
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 15th Jan 2020 20:53
I know this was answered already with excellent code. But as for the question on how else to do this, in maybe a potentially equally or more efficient way... Instead of using a flag to set whether a weapon is available or not, you could also add whatever weapons you've picked up ingame to a dynamic list (an array too, which resizes based on the weapons picked up). Then just use dec or inc to scroll through the temporary list which can only ever have weapons you actually picked up.

Login to post a reply

Server time is: 2024-04-16 08:12:31
Your offset time is: 2024-04-16 08:12:31