Issue accessing struct in Game class
-
- Posts: 432
- Joined: September 26th, 2013, 4:57 pm
- Location: Kentucky
- Contact:
Issue accessing struct in Game class
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.
Re: Is it possible to call a function in game from outside g
hi again , 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
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 --
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 --
-
- 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
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.
Re: Is it possible to call a function in game from outside g
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.cppPindrought 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.
yes you can, but like i said above, the function would need an instance of the class passed to itPindrought 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?
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 (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 --
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 --
-
- 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
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.
Re: Is it possible to call a function in game from outside g
lol yea, ClientThread would require a param of LPVOID to work with CreateThread
now to point out 2 things:
if you're not gonna use the HANDLE that gets returned by the CreateThread function then you should close it like so :p
(closing the handle won't destroy the thread)
edit: aslo, dam, deleting all your posts' message, now this thread is useless to read lol
now to point out 2 things:
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:// 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))
Code: Select all
recv(sConnect, (char*)&sbuffer, sizeof(sbuffer), NULL);
Code: Select all
CloseHandle(CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE) ClientThread, NULL, NULL, NULL));
edit: aslo, dam, deleting all your posts' message, now this thread is useless to read 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 --
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 --