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 / Adding +1 to ID of object, everytime it makes new cube.

Author
Message
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 13:09 Edited at: 18th Jul 2009 13:10
Hey,

Sorry for long though not understandable title.

So i have made a sprite cube. And when you click on it, it would make a object cube in the middle of the matrix. That works.
But if i click on it again, it wont make another cube as its ID already is 1. As i used this piece of code to make the cube:



Note: This is just a part of the code.

But has anybody a methode, so when i click on the sprite, it would make a cube. And then if i click again, its ID would be 2 instead of 1. and then 3, 4, 5, 6. And so on...

Anyone an idea?

Thanks,

Red Eye

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 18th Jul 2009 13:26 Edited at: 18th Jul 2009 13:27
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 13:36
Thank you a million mate , i see i can use this in different ways, thank you a bunch.

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 18th Jul 2009 14:01
no problem, you're welcome
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 18th Jul 2009 15:05
you could write it as:

which I find neater.

Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 16:18
It is indeed a bit neater, thank you both, mates.


Red Eye

Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 18:06
Thank you guys, but now everyime if i hold the icon, it will add cubes. Is there a way to prevent this.That he just adds on every click:

Her is my code:


Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 18th Jul 2009 18:17 Edited at: 18th Jul 2009 18:19
You can do something like this:



Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 18:40 Edited at: 18th Jul 2009 18:44
Ok, cool thanks mate, gonna try that.

EDIT: Am i missing something, or that code doesnt work?

Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 18th Jul 2009 19:09
It should work; It ran fine for me when I tried it. You wanted to add a cube every time the mouse's left button is clicked on the icon and not held, right? What happens?

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 19:15
1>.\Main.cpp(161) : error C2065: 'lastMouseState' : undeclared identifier

This error.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 18th Jul 2009 19:15
Quote: "everyime if i hold the icon"


Bear in mind that dbMouseClick() will report the mouse click every time you ask, once you've clicked it, until you release the button. You need to track the last click status of the button and retain it. Then use some testing to see if the button is still being clicked after previously being clicked or just released after previously being clicked.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 19:29 Edited at: 18th Jul 2009 19:29
We posted at the same time. Lilith, thanks mate. I am workig on it, thought the script that Bran flakes91093, showed me gives me a error:

1>.Main.cpp(161) : error C2065: 'lastMouseState' : undeclared identifier

This error.

Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 18th Jul 2009 19:31
Quote: "1>.\Main.cpp(161) : error C2065: 'lastMouseState' : undeclared identifier

This error."


Maybe you didn't define it?



Put that in the function like I posted before:



Or declare it as a global variable at the top of your program.



Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 19:41
I did. But now he doesnt give me error, but only a black screen.
I tried with int on top of my program, bu yet again, black screen.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 18th Jul 2009 19:43
If you're brave enough take a look at the following post. It's a Mouse class I wrote (and still haven't updated due to my schedule) that deals with issues like a button being just clicked or just released.


http://forum.thegamecreators.com/?m=forum_view&t=131456&b=22

There may be some changes you'd like to implement based on the discussion that follows and the fact that I never tackled the Z direction issues like I should have. And some of the code can be shrunk but I left it it in a working mode because the logic I'd initially developed didn't work but the shrinking of the working code looks suspiciously like the code that didn't work.

AAR, using the class or not, the logic is there to be used if you'd like to study it for your own purposes.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 19:46
Ok thanks mate, i will take a look.

Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Jul 2009 19:57
Dont Thank you all mates, really thanks.

I putted a } too much. Really sorry mates..


AND THANKS

Turoid
20
Years of Service
User Offline
Joined: 1st Nov 2003
Location: The Netherlands
Posted: 19th Jul 2009 01:18
There are many ways to do this. You can also create a function to return a 'free' object ID. With this function for example:



You could use that then with your existing code like this:



Works very nice if you just want to create some objects. But it also has its downsides. Its not super-uber fast, you have to do a linear search through all ID's which are not available. And when you want to know how many objects you have you should do another kind of linear search, instead of knowing directly what the object count is in your scene.

I use it mostly with a linked-list system. In a way I never have to worry about my object ID's. Small example of what I mean:



Posibilities are endless!


Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 19th Jul 2009 14:08
Ok thanks, I will try that methode too. Thank you.

Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 23rd Jul 2009 23:42
Ok i ran to a problem. I have 2 files.
1. Main.cpp
2. functions.h

So all functions will go into the functions.h. And yes i have included the file, into the Main.cpp.

Now i have this trick: (cone for example)



With Cone Cylinder and Plane. All work but suddenly after alot of code in While in Main.cpp it wont let me click mutliple times.

Is this cuz i have put alot of code in the while of the main.cpp?

Thanks,

Red Eye

Login to post a reply

Server time is: 2024-10-01 08:50:52
Your offset time is: 2024-10-01 08:50:52