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 / int to char* - error C2664

Author
Message
xiva
15
Years of Service
User Offline
Joined: 16th Apr 2009
Location:
Posted: 20th Jun 2009 20:22


I am trying to use dbText to show on screen how many lives the player has left. When i try to show int lives using dbText (510,3,lives); it gives me:
1>c:\users\j\documents\visual studio 2008\projects\space noobs\space noobs\main.cpp(25) : error C2664: 'dbText' : cannot convert parameter 3 from 'int' to 'char *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

Im pretty new to DarkGDK and c++ so help will be appreciated

Thanks

"Lifes like a box of chocolates, you never know which one you get" Forest Gump
Unless you read the leaflet, thats why hes so "different"
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 20th Jun 2009 20:32


Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 20th Jun 2009 20:37 Edited at: 20th Jun 2009 20:38
Several things you can do:

DarkGDK Method:



Plain C++ ( Better )



It may also be possible ( haven't tested ) to do it in one line as such:



Finally one other method:
This one is a bit more useful as you can change the "%i" to a "%f" for displaying float values. Also a trick I learned, "%.0f" will display a float value with no decimals, "%0.1f" will display a float with 1 decimal value, and so on.


xiva
15
Years of Service
User Offline
Joined: 16th Apr 2009
Location:
Posted: 20th Jun 2009 20:47
I've just tried using dbText( 510, 3, dbStr( lives ) ); and it gets rid of the error but i still can not see the text. At the top i have declared int lives = 3;

"Lifes like a box of chocolates, you never know which one you get" Forest Gump
Unless you read the leaflet, thats why hes so "different"
Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 20th Jun 2009 20:50 Edited at: 21st Jun 2009 09:51
It's because you are writing the text outside of the game loop.



Your dbText command should be somewhere in the while loop, or else it just gets drawn once and then erased as soon as dbSync is called again. Even if it didn't get erased, it wouldn't display with the current number of lives since it's only being called once outside of the loop.

xiva
15
Years of Service
User Offline
Joined: 16th Apr 2009
Location:
Posted: 20th Jun 2009 21:12
Thanks it's working great.
Many thanks for the quick responses!

"Lifes like a box of chocolates, you never know which one you get" Forest Gump
Unless you read the leaflet, thats why hes so "different"
xiva
15
Years of Service
User Offline
Joined: 16th Apr 2009
Location:
Posted: 20th Jun 2009 21:46
Thought i might aswell post here instead of starting a new thread.
1. In my space invaders clone, how would i go about coding the shooting of the bullet so that i can fire bullets in a machine gun fashion.

2. How would i code so that the bullets "Stick to me". By this i mean that i can fire them from my current position.

Im not looking for somebody to give me the code, but maybe to give me an idea, seudo code, or just a link to some tutorial/help.

xiva
xiva
15
Years of Service
User Offline
Joined: 16th Apr 2009
Location:
Posted: 20th Jun 2009 22:34
bump
Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 21st Jun 2009 01:51
Quote: "1. In my space invaders clone, how would i go about coding the shooting of the bullet so that i can fire bullets in a machine gun fashion."


Create an array of bullets in this fashion ( NOTE, this requires having a class called BulletObject )
BulletObject Bullet[50];

Then when the player shoots, simply 'activate' one of the bullets and position it where the player is, aka Bullet.x = Player.x, and so on.

Then you can have a loop which watches the array of bullets, and updates/moves them as necessary.

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 21st Jun 2009 09:20
Use one of Phosphoer's suggestions to output the text, 'dbText( 510, 3, dbStr( lives ) );' will cause a lot of memory leaks after you call it many times.

Login to post a reply

Server time is: 2024-10-01 06:07:18
Your offset time is: 2024-10-01 06:07:18