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 / Selecting an object in an array

Author
Message
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 3rd Mar 2009 10:41
im currently using



using this i try drawing another ellipse in the same position as the first but it only works when i have the mouse over one of them and the left key down, i would like it to stay selected until another is selected...

any help with this would be greatly appreciated!...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 3rd Mar 2009 11:20
2 Things.

Firstly you don't need to use else if together like that



Is how its supposed to work. It took me a while to work out why you had an extra endif command.

This is what you'd put


where as the compiler is seeing it like this...


and secondly, I didn't really have enough of your code to run it. But I think what your problem is is that you'r reseting the selected variable every loop.

You have these two lines right next to each other, so even on a slow pc we're talking thousandths of a second; not enough time for the user to let go of the button.



Are you sure you want to make object(T).selected=0? Or have I misread your code?

I made a short example of what I think your trying to do; so please look through it and see if it can help in your program



Did you want a selected object to become unselected when the user clicks on an empty space?

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 3rd Mar 2009 11:24 Edited at: 3rd Mar 2009 11:29
thankyou for posting that up very helpful

Quote: "Did you want a selected object to become unselected when the user clicks on an empty space?"


no, i would like it to deselect the current ellipse when another one is selected.

EDIT1: i just read though what you have given me and its checking the position of the mouse based on a static object, in my game the objects that the ellipses are referencing to are planets in a solar system and i have been trying for some time to get my code working so that i may release another version..

in another case i will provide you with the whole subroutine for drawing the radar and the not working select code..




thankyou for your help and time..
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 3rd Mar 2009 14:20
have you tried just removing this line?



What happens when you do?

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 3rd Mar 2009 23:51
it does nothing at all, so ill leave it out.

i just changed the array (object(T).selected) to rselect and it now keeps the ellipse there but draws it on all of them not just the one. i may need to change how they were created so that i can better look for which one is being clicked on, but i wouldnt know where to start...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 4th Mar 2009 00:02
In my example, with the static buttons; the variable selected contains the number of the object pressed.

It then checks this, and draws a circle round the relevent object.

I'd assume it'd work the same way with yours? Use a variable to store the number of the selected object, then outside of the "checking to see if its been clicked" bit; check to see which object has been selected, then draw a circle round it.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 4th Mar 2009 00:38
the problem im having is that the code to check my mouse position



is updating every loop and that checks for all of the ellipses so there are no real identifiers.

i need a way of adding an identifier to each of the ellipses so that i can then check which one was clicked, i had thaught about using 3d objects instead to do this but it would up the poly count heaps and become quite annoying to actually make them stay with the screen and move about the radar at the same time...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 4th Mar 2009 02:15 Edited at: 4th Mar 2009 02:16
I think I'd be able to help you more if I could see your entire code (and media so I can run it); but I can't imagine how you've been trying to do this without a numerical identifier for each object.

To set up the stars/planets/moons; I'd probly use a type set up roughly like this.



this would allow me to represent them either in 2d with boxes/sprites or in 3d with objects.

I'd then either compare mouse/object co'ords in 2d (like I did with the buttons, it'll still work even if the're moving) or if I were using 3D objects then maybe the pick object command will tell me what object is under the mouse in 3d space.

So, if the LMB is pressed whilst over a valid object, then set the value of the selected variable to which ever object you just pressed on.

Using this value, you can reference the co'ords to draw the circle round it.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 4th Mar 2009 08:48
is there a way that i can send you my project without anybody else viewing?

p.s. i already have the planets set up with a type, so thanks anyway. I also have the 'objto' and 'objfrom' variables used to reference the planet/moon objects and even the camera to show up...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 4th Mar 2009 10:59 Edited at: 4th Mar 2009 11:00
I've added my email address to my forum details, so you should just be able to zip up your project and email it to me

But if your using a dim'd array to store the planets data, can you not use its array index (the n in planet(n) in the type example I gave earlier) to identify which planet you need to draw the circle around?

Anyway, send me your project and I'll have a look and see whats going on

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 4th Mar 2009 11:48
im sending it now.

my planets are not in an array and i am drawing these ellipses around another ellipse wich is reperesenting the position of the planet on a 2d radar...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 6th Mar 2009 18:04
Ok, well, It's taken me a little while. Lol

You really could have put some more comments in, It took me the 1st day just working out what all the variables and gosubs did.

It now however, highlights a planet on the radar when u click on it, and it stays highlighted until you select another planet.

I've commented the code so u can see what I've done.



Hope thats more like what your after.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 7th Mar 2009 01:37
thankyou soo much, i knew that the problem would be small...

i can now move on to other things.

one question is there a way to get the mouse position for where it is clickable to have a radius so that i dont have to click in the center??
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 7th Mar 2009 12:28
The planet checking line in your code is this



Which checks if you've clicked 2 pixels radius from the centre of the elipse. (2^2=4), so for a larger radius, just increase the number at the end. 25 (5 squared) will give you a 5 pixel radius.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 7th Mar 2009 12:41
thanks for that heaps..

i actually got in in a pile of snippets and didnt fully understand it....
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 7th Mar 2009 18:35
No worries

Glad you got it all working now

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@

Login to post a reply

Server time is: 2024-11-25 10:44:30
Your offset time is: 2024-11-25 10:44:30