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 Discussion / loop for multiple objects (mr.program respond)

Author
Message
koolaid
22
Years of Service
User Offline
Joined: 26th Jan 2003
Location: Cyberspace
Posted: 24th Mar 2003 10:42
okay so i was told that instead of loading the same object over and over if im going to use it multiple times i could create a loop.

for a = 1 to 5
load object "big asteroid.x",a
next a

how could i position them in 5 different places
do i
position object a,,0,0,0
and position another object a at a different place
below is what i originally had i want those objects at those places but dont wont to load it such and such times.




if you could please put how you would make a loop to position them
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 24th Mar 2003 15:17
here is an example of using a simple for loop



koolaid
22
Years of Service
User Offline
Joined: 26th Jan 2003
Location: Cyberspace
Posted: 24th Mar 2003 23:24
okay heres what i put:i want the object to load once and have one in each of those 5 coordinates.its not working right im getting errors.

for a= 1 to 5
load object "big asteroid.x",a
position object a,8655,10,7008
position object a,8150,-5,7285
position object a,8975,-5,8144
position object a,7667,23,5965
position object a,8147,16,5536
next a

whats wrong?
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 25th Mar 2003 02:33
u will have to remove the hard coded position commands and replace the a with a number for each one if u want those positions exactly.

koolaid
22
Years of Service
User Offline
Joined: 26th Jan 2003
Location: Cyberspace
Posted: 25th Mar 2003 07:29
so if i do that how is the loop suppose to look (for a = 1 to 5)do i put the start off number of the object instead of a because i want 5 of them,and to be objects 49-53 at specific positions
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 25th Mar 2003 09:09
u could do this per say


for i = 1 to 5
position object i,0,0,i*100
next i


this places them at a division of 100 but times this each loop
100
200
300
400
500

as u can see this places them in a row if they were created previously.

for any odd placements its best to place them manually


----------------------------


u can also do this


for i = 10 to 20
position object i,0,0,i*2
next i

its a simple solution to working with objects that are not in the starting range of 1 to whatever.



----------------------------

u could also do this

randomize timer()
for i = 1 to 5
position object i,0,0,rnd(1000)+1
next i

this places 5 cubes on the z dimension randomly between 1 - 1001


----------------------------

for i = 1 to 5
if i = 1 then position object 1,110,10,100
if i = 2 then position object 1,0,10,100
if i = 3 then position object 1,10,10,100
if i = 4 then position object 1,0,110,100
if i = 5 then position object 1,0,1110,100
next i

its easier just to use the manual placement as you can see.

----------------------------

if your models are in object spaces 10 - 20
you could do this

for i = 1 to 10
position object i+10,0,0,i*100
next i

this uses the i in the loop but adds 10 to it in the media location and times it by 100 when placing it on the x dimension.

----------------------------


now that ive explained these methods have a look at what im doing with the one way at the top.

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 25th Mar 2003 09:10
typo

for i = 1 to 5
if i = 1 then position object 1,110,10,100
if i = 2 then position object 1,0,10,100
if i = 3 then position object 1,10,10,100
if i = 4 then position object 1,0,110,100
if i = 5 then position object 1,0,1110,100
next i

should be this

for i = 1 to 5
if i = 1 then position object 1,110,10,100
if i = 2 then position object 2,0,10,100
if i = 3 then position object 3,10,10,100
if i = 4 then position object 4,0,110,100
if i = 5 then position object 5,0,1110,100
next i

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 25th Mar 2003 09:19
now if u want to go deeper into arrays and types u can however work on these concepts first then u will want to store these co ordinates of each item into an array or a type so its accessable over functions as your program grows in size.

dont worry about all of this just yet and learn up on the loop methods as u use these later down the track.

koolaid
22
Years of Service
User Offline
Joined: 26th Jan 2003
Location: Cyberspace
Posted: 26th Mar 2003 02:57
thanks i used that last solution it worked out solved me writing load over an over explain more on your first method im mean the last one is easier right.in my other post on this the idea of static objects was mentioned can this make things run faster indi.

Login to post a reply

Server time is: 2025-05-17 19:28:22
Your offset time is: 2025-05-17 19:28:22