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 DBPro Corner / For next loop help

Author
Message
the destroyer
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 20th Mar 2009 11:05
Hello I have a Game and I want to make many boxes and position it the position I want but I can't do it with the for next loop
here is an example

please help me
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 20th Mar 2009 11:52
It depends on where you do indeed want them positioned?

You could write position object b, (b - 1) * 10, 0, 0
to get them all positioned next to each other on the x axis, beginning at the coordinates (0, 0, 0), for example.

the destroyer
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 20th Mar 2009 11:58
Thanx for the reply but I want to make a platform game so that the player jumps on the boxes, i have set up the collision system and jumping
here is my whole code
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 20th Mar 2009 12:40
How's about this then?


(I changed the player's initial position and set up the boxes like so:
1 2 3
4 5 6
7 8 9)

the destroyer
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 20th Mar 2009 13:13
Thank you so much that is what i wanted but one last thing is to explain to me how you did so I can dot it my self
thanx
and by the way can you speak swedish cuz I live in sweden in borås
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 20th Mar 2009 13:32
Ah, trevligt med fler svenskar!
Tar förklaringen på engelska för eventuella andra läsares skull dock;

You wanted to have 9 objects. To position them one by one in 3x3 rows, it is easiest to have two nested for loops counting to three each (should you have any other number than nine, this would be the square root of that number). To ease the positioning near (0, 0, 0), I let the for loop go from 0 through 2 instead of 1 through 3, and then just added 1 to the object value.
Since 0 * 3 + 0 + 2 = 2, 0 * 3 + 1 + 2 = 3, ..., 2 * 3 + 2 + 2 = 10, the object ID count will go from two to ten using that method as well as just "for obj = 2 to 10 : make object obj..."

Anyway, bx is then the column that the box is supposed to spawn in, and by the row. So, by multiplying these values by the object's size * 2 when positioning them, we get a space equal to the object's size between each object as well.
And that's about it, I think.

(I fear I blow () at explaining this though, so if there's any specific question, feel free to ask).

the destroyer
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 20th Mar 2009 14:14
haa I can't understand.... why did you use two neasted loops and why did you multiply mx and my with 2
can you explain it little simpler
thanx
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 20th Mar 2009 21:17 Edited at: 20th Mar 2009 21:55
Hmm... Taking Rudolpho's code, this may be a little easier to understand. It does the same thing:



I just changed the way it handles object numbers.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 21st Mar 2009 00:08
Yes, Sixty Square's explanation was pretty good.

About the nested loops, they were supposed to ease the positioning work, as we wanted the boxes positioned in a row by column pattern.
Then, as Sixty Squares said, for every bx (column), there will be added a box for each row and positioned accordingly (bx * 200 = 200 times the current column, by * 200 = 200 times the current row).

the destroyer
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 21st Mar 2009 15:54 Edited at: 21st Mar 2009 16:23
Alright thanx for that, I get this part but what if I want to increase the number of boxes and want them to be positioned random in the x and y axes and not in the same place
one more thing how do I make them for example thicker and then smaller I mean I changed my code to this


I made stairs instead of boxes I want them to be smaller in the top
try the game and you'll understand what I mean
beceause I want he stairs to be 200,20,500 and start changing to 100,20,50
I think you understand now thankx
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 21st Mar 2009 16:39 Edited at: 21st Mar 2009 16:40
Do they have to just only change to that specific size?
In such an event, use something like this:


Or if you want them to decrease all the way up to the top, you can just decrease the size values with a multiple of bx.
Example:


(That's some long stairs, by the way )

the destroyer
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 21st Mar 2009 17:25
thats what i wanted thankx, by the way can I add you msn? you really can help me.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 21st Mar 2009 23:07
I guess so...
Det är samma adress som e-postknappen leder till.

Login to post a reply

Server time is: 2024-09-28 04:21:04
Your offset time is: 2024-09-28 04:21:04