Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Game Programming (http://www.xtremevbtalk.com/-net-game-programming/)
-   -   Using Loops or Arrays (http://www.xtremevbtalk.com/-net-game-programming/327161-using-loops-arrays.html)

Marred 07-12-2014 04:01 PM

Using Loops or Arrays
 
So I'm rather new to Visual Basic. Been using it for a couple months now, however I'm not too familiar with how to use looping and arrays. My game that I'm currently making uses a lot of timers. I'm not done the game but I think there's going to be 40+ timers.

My main question is, how can I implement this coding:

http://pastebin.com/iYcS3p0s

into a more efficient way? I know I can try looping but I'm not sure how to use variable names as part of the loop counter.

And with arrays, I'm just not too familiar with them at all.

Thanks

PlausiblyDamp 07-14-2014 05:44 AM

http://www.xtremevbtalk.com/tutors-corner/174835-control-arrays-net.html should give you an idea of how to use arrays when working with controls.

Marred 07-20-2014 10:02 PM

Thanks for the reply! Much appreciated for showing me, but I have just one more question. Most of my coding is being blocked and put into individual timers. The thing is, I have twenty plus timers. Is this okay? Almost all of them are running every ms and I'm wondering if there's an alternative to this.

I looked up multi-threading but it seems too complex and unnecessary for a simple game like the one I want to make.

Marred 07-20-2014 10:04 PM

Thanks for the reply! Much appreciated for showing me, but I have just one more question. Most of my coding is being blocked and put into individual timers. The thing is, I have twenty plus timers. Is this okay? Almost all of them are running every ms and I'm wondering if there's an alternative to this.

I looked up multi-threading but it seems too complex and unnecessary for a simple game like the one I want to make.

Edit: ...what >.> I clicked to submit the reply then it led me to the go advanced editting, so I thought the post didn't go through so I clicked it again and it seemed that I replied twice -.-

PlausiblyDamp 07-21-2014 06:19 AM

Could you not just use a single timer and do multiple things every time it fires? 40+ timers sounds rather a lot.

Marred 07-21-2014 08:38 AM

Oh, well yes actually I can do that. The problem is that I want to be able to, in other block of code, tell which timer that's looping a certain action to stop. Another thing is that for example if I have two enemies, if I have them randomly moving I don't want the interval for both of them to be the same so both of them change directions at the exact same time, which would seem a bit odd.

What I have set up for that case is one timer that RND's an interval for the enemy timer. The next timer then waits for it's wait to finish then it turns on a third timer, the second one turns off, then the third one changes direction of the enemy and moves it.

There are a number situations, but yeah there are others where I could jumble into just one timer, I can definitely do that. I also just thought it would have been a bit easier the way I currently have my game set up since it's easy to find the code that I want rather than a lot of different things that would be hard to put under one name.

PlausiblyDamp 07-22-2014 03:36 AM

Quote:

but yeah there are others where I could jumble into just one timer, I can definitely do that. I also just thought it would have been a bit easier the way I currently have my game set up since it's easy to find the code that I want rather than a lot of different things that would be hard to put under one name.
This all ultimately comes down to code organisation, having individual functions for individual tasks that may be called from a single timer will make things cleaner, using classes to group related data and functionality together will also be a big help.


All times are GMT -6. The time now is 11:36 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.