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.

Dark GDK / A 'for' Problem

Author
Message
zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 31st Jul 2009 17:25
I loaded an object [square-like model] 9 times using GDK. What I'm trying to do is position that object, something like this:

But I can't do it right.
Here's what I tried so far:
Attempt1:

Attempts2:

Any ideas what am I doing wrong?
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 31st Jul 2009 17:54
9 x 3 x 3 != 9.

Follow your loops through in your head and you should see the issue.

zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 31st Jul 2009 18:11
9 x 3 x 3? I really don't get what you mean. Let's split it down a little and see what am I thinking wrong.
What do I have? 9 square objects.
I want to position them like the numbers on the num pad, from 1 to 9.
What does this mean? That I have 3 squares / row and 3 rows.
Now by doing a for from 1 to 9(WorldObjects) I can use dbPosition to position all of my objects at the given coordinates.
[... kinda hard to explain ...]
Now by doing:

I try to position the objects like this
worldobject(1) at 1,1
worldobject(2) at 1,2
worldobject(3) at 1,3
worldobject(4) at 2,1
.....................
worldobject(9) at 3,3.
But yet, I still don't know/understand what am I thinking wrong? 9 X 3 X 3 != 9, but I need the first "9" so I can loop through all my objects. hm...
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 31st Jul 2009 18:14


Let me know if that does not work.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 31st Jul 2009 18:21
You're looping through all 9 objects yes, but you then you go through a 3x3 loop which is done on ALL the objects, thus all 9 get given the SAME position at the end of all the loops.

matty halewood's code should do what you need, though I prefer giving people hints rather than giving them the final code but whatever.

zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 31st Jul 2009 18:27
Well, I didn't want the code, I just wanted to know what was wrong with my way of doing it! Thanks matty, but I will look over your code if I can't find a way to do it on my own. Thank you dark coder for enlightening me.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 31st Jul 2009 18:33
Strange help thread, lol.
Necro_100000
15
Years of Service
User Offline
Joined: 31st Jul 2009
Location:
Posted: 31st Jul 2009 19:06
See if this helps out...

Look at your WorldObjects loop.

Now this evaded me at first to, but if you look each WorldObjects is being calculated 9 times.

As matty halewood did try moving WorldObjects inside the loop instead of outside.

This is because as it is now your giving each WorldObject this,
1, 2, 3
1, 2, 3
1, 2, 3

Then you move onto the next WorldObject.

Another method you could look at is making int i and int j outside of the loop then just use i++ and j++ to increase your position.

Example:


with this we would get an out put of something like this where j = x and i = y...

1, 2, 3
1, 2, 3

Hope that helps but your going to have to come up with the rest of the code yourself.

Login to post a reply

Server time is: 2024-10-01 08:40:13
Your offset time is: 2024-10-01 08:40:13