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 / OK! I have to ask!

Author
Message
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 25th May 2013 15:09
Can someone explain how to get dbInput to work with an int. I have done searches and just can't get it to work right. I don't have a full and complete understanding of pointers and references but am gaining on that. I am documenting these as I am going along.

I finally got the string thing down and now need to learn about dbInput()

I want int choices like this

1. Start game
2. End game
Choice:

If 1. is picked the game starts 2. game ends

and also when they pick 1 or 2 it shows right away next to choice not after they hit enter. The choice should show right away when they type it in and when they hit enter they should be taken to the phase of the game they chose.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th May 2013 16:37
I think dbInput() doesn't work right..... I use dbGetEntry(). It's the async version of dbInput(). To use this, you will have to make an interface that will capture the input in a loop.

The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 25th May 2013 16:59 Edited at: 25th May 2013 17:00
Well here is my total code with dbGet entry used. I have tried every example I could find to get dbInput to work and nothing does. I really want to use these color and 2D commands but can't get things working and I am wasting a lot of time trying. If I can't get a handle on GDK pretty quick I am going to have to go back to normal c++ and or DBP and figure out something else for c++!

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th May 2013 20:20
dbGetEntry() returns a string value (not std::string).


I think I understand your original problem now that I see your code. When you use dbInput(), it returns a string value. You have to convert the string into an integer value to make your "if" statements work. Convert your code back to the way you had it and re-post it......

The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 25th May 2013 21:25



I have also tried choie = dbInput but didn't work
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th May 2013 22:37 Edited at: 25th May 2013 22:38
dbInput() returns a char*. You will have to convert the string into an integer to do what you are wanting.



http://www.cplusplus.com/reference/cstdlib/atoi/?kw=atoi

The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 26th May 2013 00:58
I get this error

error C2440: '=' : cannot convert from 'char *' to 'char [100]'
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th May 2013 02:17 Edited at: 26th May 2013 02:19
That's odd... Show the entire code.


EDIT:
Actually try this:


The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 26th May 2013 04:33
Here is the code, I may have not put it in the right place. I get the same error with the other that is now commented out.

Brendy boy
18
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 26th May 2013 10:12
Quote: "char choice;"


Quote: "if(choice == 1)"


1 isn't a string, it's a number

choice needs to be int not char or you must compare two strings ( choice and "1"). You cant compare char and int

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 26th May 2013 12:07
As Brendy Boy said, you can't compare different data types unless you cast them. If you want to check if the user inputted the number 1 then you would do:
Quote: "if (choice == '1')"


or if you wanted to use int's you could convert the numbers to char's:
Quote: "if (choice == (char)(((int)'0')+i))"


I recommend the first option

Off Topic: Hey Brendy Boy, did you ever release your Landscape & Map Creator?
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th May 2013 17:11 Edited at: 26th May 2013 17:14

To avoid confusion again, I moved everything into place.
"choice" was fine as an "int". You only needed a way to convert the characters entered by the player to a number (int)--that's what the "choice=atoi(buff);" line was for. The "sprintf_s(buff,100,"%s",dbInput());" line was to copy the input into something "atoi" could read.

Don't give up. C++ is MUCH more powerful than basic. With this greater power comes a steeper learning curve.

The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 26th May 2013 20:58
That worked Thanks, now to study and play around with it so I can figure out how to get it to do what I want.

One thing I am having a hard time understanding is why the player input had to be changed to an int? I understand that 1 is a character and also a number. It seems to me that DGDK can't tell the difference

If I code this in normal c++ and VS it works without all the conversion code. The only problem I have with normal c++ and visual studio is no native graphics commands and screen formatting ability, or very little. I want to be able to create screens, put my text here or there etc... Can't do it in c++ unless you know DX, SFML or SDL. I would prefer to use DGDK because I know a lot of the DBP commands already which makes things a lot easier.

Another thing I don't get is why would they make a product with commands that don't work unless you do other stuff to get it to work and then not clearly document that so you know!

I have no experience in C at all and not enough in C++ to know this stuff needs to be used. It seems to me that DGDK is one big workaround to get things working. I am not giving up on it yet but I need to get a handle on this conversion stuff then things may get a little easier.

I have a good project going in DBP and I would like to port it over to DGDK and continue on with it.
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 26th May 2013 22:25
Quote: "It seems to me that DGDK is one big workaround to get things working."


I whole heartily agree

I have been using DarkGDK for years now and I have had to learn a lot of native DirectX to get around some of the problems GDK has.

DarkGDK is powerful because of its ease of use, but with that ease of use comes slowdowns (drawcalls ) and problems (to many to say) but I like DarkGDK because of this ease of use and it doesn't bother me that I have to use native DirectX code to extend or fix features, I like DarkGDK, I don't know why, even after using Ogre3D for around a year I still came back to GDK.
Brendy boy
18
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 27th May 2013 03:18
Quote: "Off Topic: Hey Brendy Boy, did you ever release your Landscape & Map Creator?"

no, i haven't. I didn't have time to work on it for the last 3 years so it's still quite unfinished

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 27th May 2013 06:03
Quote: "One thing I am having a hard time understanding is why the player input had to be changed to an int? I understand that 1 is a character and also a number. It seems to me that DGDK can't tell the difference
"

DGDK is using C++ environment/compiler and therefore must conform to its standards. DBP is its own compiler and therefore can be cast as any type TGC creators made it to be.

The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 27th May 2013 16:36 Edited at: 27th May 2013 16:42
DarkGDK code does not run as is. Can be made to run with extra coding but does not work with DarkGDK commands right out of the box.



The same code in normal c++ visual studio 2008 runs fine with no extra work.



Quote: "DGDK is using C++ environment/compiler and therefore must conform to its standards.

DBP is its own compiler and therefore can be cast as any type TGC creators made it to be.
"


I understand both these statements what I don't get is why normal c++ same code works and DGDK does not.

This is the error I get when I run the GDK code

error C2440: '=' : cannot convert from 'char *' to 'int'

Extra work and coding needs to be done to make it work, extra things to learn, extra things to remember, extra time spent trying to figure it out and waiting for answers from the forum because DGDK was not documented properly to begin with.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 27th May 2013 18:52
Function calls return specific "types" of info (if they return anything). dbInput() is designed to return a char* not an int. This is not something to get worked up about. It's just the way they wrote it and I don't think they are going to change it any time soon......

The fastest code is the code never written.
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 27th May 2013 19:03 Edited at: 27th May 2013 19:08
Dragon Slayer, you need to use two equal signs when comparing varibles in an if statment, so this:
Quote: "if(choice = 1)"

becomes this:
Quote: "if(choice == 1)"


One equal sign means you are transferring data values, two equal signs means you are comparing the varibles.

Also, You cannot compare an int and a pointer to a char (char*), make the variable choice a char* and do this: if (choice == "1")
Boca
13
Years of Service
User Offline
Joined: 25th Nov 2010
Location:
Posted: 27th May 2013 19:09
In your first example you prototype the functions

void startGame();
void endGame();


then in the dark gdk function you call them but they have not been defined..so they will do nothing since there is no code for them.

as far as the cannot convert from char* to int this has been answered in many of your posts. You must remember that dark gdk for what ever reason uses C for input and as far as I know for output,, C++ is best used ( IMO ) with strings, and cout and cin are both great with this. But if you declair something as a char and then try to put it out and or take it in then you must convert it to that,

for example



string plrname;
string holder ( "Adventurer" );// give a default name

//say I now have a class called player and I have a setter for the players name.
player->setPlrName(holder);
or
player.setPlarName(holder); the difference would be in your code
depending on how you reference your functions and how you pass arguments
// so I must if useing darkgdk print out a String, something I as
the programmer must do. So I would have to make the C++ string go to C

void showPlayersInfor(Player *player)
{

dbSetCursor(500,50),dbPrint("Name - ") , dbSetCursor(580,50), dbPrint((char*) player->getPlrName().c_str());
//so now I can print out with dark gdk a string
}

[\code]

remember that is just a sample and for it to work for you, you would need a players class and setter, getter functions, If you need to see this working I will put one together for you..
Boca
13
Years of Service
User Offline
Joined: 25th Nov 2010
Location:
Posted: 27th May 2013 19:11 Edited at: 27th May 2013 19:13
sorry this was a double post
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 28th May 2013 01:13
DarkGDK is just the DBPro functions wrapped up in a set of C++ libraries. If your we're to write a function In C++ that returns a character pointer, you wouldn't expect it to return an integer. The C++ standard input/output functions are overloaded this is the reason your second snippet works. dbInput on the other hand is not overloaded it returns a character pointer only.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 29th May 2013 02:10
I know what overloaded is Couldn't these functions be overloaded? The source is out there right?
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 29th May 2013 02:53
True. If you want to make these kinds of changes, be my guest--TGC isn't..... This kind of modding takes time, time you may not want to spend, time you could be spending on making a game.

The fastest code is the code never written.
Dragon slayer
17
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 29th May 2013 03:38
Doing that is something I don't really know a lot about. I briefly looked at the D/L page, saw something about a SVN editor not sure what that is all about. Might be something to fool with maybe learn some things sometime. When I have time which I have very little of now.

Login to post a reply

Server time is: 2024-04-25 08:11:35
Your offset time is: 2024-04-25 08:11:35