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.

DarkBASIC Professional Discussion / Help with making a for loop for walls

Author
Message
Dark Basic Pro Enthusiast
12
Years of Service
User Offline
Joined: 8th Nov 2013
Location:
Posted: 6th Mar 2014 17:01
Hey I am working on a game and making walls that are taking up too much lines of code and I need a way to make a for loop for the walls but do not know how to....Help Please?

the loop is so you can move around and see stuff please help

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 6th Mar 2014 18:05
Well, you just have to find out what's equal for all created boxes and where exactly the differences are.
Generally you're giving each of your objects similar properties - position, rotation, color and texture. So one way to make the whole code a lot more readable would be to create a function handling the wall generation after taking the standard values as parameter, sort of like this:



Putting this below your code you could then add the boxes like this:



instead of




Still not a for loop, but already way easier to read and work with.

Generally you're right, a for loop would be nice in this place. However, this is kind of problematic given that your boxes seem to be placed relatively arbitrarily and you can't just create a formula to calculate the size, position and color of each object based on its ID. Hence a for loop would first require an array containing the individual size, position and color data for each of your objects. This however means that you would have to start by filling an array with these values - given the scope of your project, it's probably the easiest and most efficient solution to just use the function method as demonstrated above.

For bigger projects, you would probably use an editor to place and size all the objects manually, the editor would then write the values to a file and your game would read this file (possibly using a for loop) and create the walls based on the values stored there.


Also, this is a relatively simple example of how to create a group of objects directly with a for loop, by making the parameters (in this case position and rotation) depend on the loop variable:



(the numeric values within the for loop are pretty arbitrary and merely there to make the thing look a little more interesting)

Dark Basic Pro Enthusiast
12
Years of Service
User Offline
Joined: 8th Nov 2013
Location:
Posted: 7th Mar 2014 17:10
Thank you this is easily understandable and this will help me in the future for making functions because I didn't understand the functions very well thank you

Login to post a reply

Server time is: 2026-07-06 10:00:14
Your offset time is: 2026-07-06 10:00:14