Issue accessing struct in Game class

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

Issue accessing struct in Game class

Post by Pindrought » November 16th, 2013, 2:49 pm

Read 5th post
Last edited by Pindrought on November 17th, 2013, 12:38 pm, edited 2 times in total.
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Is it possible to call a function in game from outside g

Post by LuisR14 » November 16th, 2013, 3:09 pm

hi again :P, why not just set Me in the Game constructor?

well anyways, you'd have to do that in the Winmain function in windows.cpp, after the Game object has been created :), you can just use your public changecoords function directly instead of using that middle-man function SETCOORDS lol
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

Re: Is it possible to call a function in game from outside g

Post by Pindrought » November 16th, 2013, 3:25 pm

read 5th post homies
Last edited by Pindrought on November 17th, 2013, 12:36 pm, edited 1 time in total.
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Is it possible to call a function in game from outside g

Post by LuisR14 » November 16th, 2013, 5:29 pm

Pindrought wrote: I tried changing my line to theGame.changecoords instead of Game.changecoords, but i'm getting error C2065: 'theGame' : undeclared identifier in main.cpp.
yea, if you changed the code you had above to this it wouldn't work since the function doesn't have a theGame, for that you'd have to pass the instance that was created in windows.cpp :)
Pindrought wrote:TL;DR Can I not make a public function outside of the game class in main.cpp that can call a function in the game class (theGame) created in Windows.cpp?
yes you can, but like i said above, the function would need an instance of the class passed to it :)

pretty much you can't edit a class since it's like a template, you need an instance of the class to be able to view, edit and execute its public data :) (unless you declare some of its data as static)

and also you can't really run code outside of the winmain( or main ) function, unless the the (win)main function called it to allow for that function to run its commands :P (not sure if this here i explained clearly lol)

(win)main calls functions, then functions might call other functions or just do some instructions then they all return back to (win)main (which is when the app then exits) :)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

Re: Is it possible to call a function in game from outside g

Post by Pindrought » November 17th, 2013, 12:28 am

Nvm got it figured out tyvm LuisR14
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Is it possible to call a function in game from outside g

Post by LuisR14 » November 17th, 2013, 4:05 pm

lol yea, ClientThread would require a param of LPVOID to work with CreateThread :)

now to point out 2 things:
// The server will send a struct to the client
// containing message and ID
// But send only accepts a char as buffer parameter
// so here we need to recv a char buffer and then
// we copy the content of this buffer to our struct

if(recv(sConnect, buffer, sizeof(sbuffer), NULL))
you can just use the struct instead of needing the char buffer :), just have to pass its address and cast it to char* like so:

Code: Select all

    recv(sConnect, (char*)&sbuffer, sizeof(sbuffer), NULL);
if you're not gonna use the HANDLE that gets returned by the CreateThread function then you should close it like so :p

Code: Select all

    CloseHandle(CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE) ClientThread, NULL, NULL, NULL));
(closing the handle won't destroy the thread)

edit: aslo, dam, deleting all your posts' message, now this thread is useless to read lol :P :D
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Post Reply