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 / Function not recieveing correct value

Author
Message
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 29th Jul 2009 08:41 Edited at: 11th Aug 2009 04:13
I am working on a lamo text based tic tac toe oriented game, the main reason was for me to become more familiar with codeing my own functions and to get used to createing more readable code, plus i was bored hehe...

note: there is a FULL source with comments at the end of the post if you need assistance in understanding the var names or their purposes

THIS IS INCOMPLETE!!
but here 8-D
ty guys i apreciate it and sorry for buggin the forum i feel nubbish



this is the code of the function, the first time the function is run it will return a value of 0 which is bad. idealy it should return a value based upon userinput...

the purpose of the boxnum function is to convert playerinput from a string form to an int for so that this function can put an x or o into the proper box..


as you can see it takes input from bnum and playerid, bnum is the specific box in which the player places his piece 1-3 top row 4-6 mid 7-9 bottom and player id is used to determine x or o (1 = x 2 = 0)

This function recieves the user's input and decides what to do based upon it.



I re-read it and it was a tiny bit shadey on the overall issue so instead of re-writing im just going to explain one more brief time...i need BoxNum() to convert from string playerInput to bNum int. The first time the BoxNum() is called it will return a value of 0 causeing the placepeice function to default. ( something worth noteing is that the line of code in the BoxNum function that out puts "defaulted" in a situation in which proper input is not recived but is passed to the function DOES NOT display showing that that function evaluates properly) The compiler outputs a warning that says there is an issue with evaluateing the first if-then statement of BoxNum() i commented out the first one and reran with the same error and i get no syntax errors either.



[edit] Download this if you do not have the runtime installed...

EYE R T3H +ick +ack +oe mester

Attachments

Login to view attachments
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 29th Jul 2009 17:12 Edited at: 29th Jul 2009 19:44
If 'playerInput' and 'bNum' are global variables, why are you passing them to functions? With the same identifier also.

What I think is happening here is that in this function:
int PlacePiece ( int bNum, int PlayerId )

When you call BoxNum(), the global variable bNum is changed, instead of the local variable bNum inside of the PlacePiece() function.

The local variable 'bNum' won't change because it is a copy of the global 'bNum'.

Try moving the BoxNum() function call here to see if i'm right before making any changes:



If that works, try changing the names of the parameters of the functions, or remove the ones where you are passing global variables to other functions that are inside of the same scope as the variables. I don't know why you are doing that.

By the way, there is a function that returns the integer value of a string.
http://cplusplus.com/reference/clibrary/cstdlib/atoi/

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 30th Jul 2009 01:50 Edited at: 27th Aug 2009 04:17
As far as the function that returns the value, I was limited the amount of header files (no particular reason though).

Ignoring that super-function of the demi gods of string-to-in conversions, the issue is occuring WITHIN the BoxNum function.

I discovered that little info after commenting out the specific function and running the debugger. the program goes off flawlessly except when a player inputs a number the placepiece() will always default (which is expected so i assume that works as well)

if you would do me the favor of compileing the source yourself ( assumeing you are useing VBasic c++ express with no altered settings) a blank cmd prompt should pop up but be placced behind the dev-env and a box in the bottom left should show all the defined variables with a + next to playerInput. expand that to see what the error is. essentially is says that the expression cannot be evaluated. My first thought was that one of the if statements were incorrect so i commented them all off one by one and the same thing kept occuring.

you were commenting about how haveing parameter's with names the same as a global variable would affect the program so maybe the issue lies within the parameter's of the BoxNum function and not the Place peice?


note: I typed that whole thing out to help me think more than anything and am now going to make the alterations to the code...

New source:



Main differences, The param in BoxNum changed from playerInput (glabal var name) to playersInput

also added a ShowGrid function to show the alterations to the vars used to store which player placed their pieces and where. To show the grid i added if-then into the PlayerInput() so that by typeing "show" you can see the alterations.

The change to the boxNum did NOT remove the warning from the compiler however when the program is run the expressions are (at least as far as i tested) evaluated correctly.

A final not that i would like to add is that if i only read my comment up at the top of the source outlineing the last issue in which a function apeared to not be reciveing proper input was solved in an identicle way i could have avoided this whole thread and for that i aopologize.

However if i have any other issues with this particular program this thread is where i will post them.

Thank you for your assistance!!!

edit:::
the compiler quit displaying the error after changeing the param name in PlayerInput() from playerInput to playerzInput

i added a few lines of code so far with easily fixed minor errors

as for now i only need features anyone who happens to read this thread may want to see in a game like this, so far i have a small todo list mostly to complete a v1.0 of the game for people to play with themselves if / when they get bored enough

[edit] updated todo-list

Done: find a way to clear screen each time the main loop is run to prevent clutter
Done: add admin status check to the player input commands used for debugging
Done: impliment a NewGame function to reset the var's so that a new game can be started without restarting the app
Done: impliment a settings enviroment where players can alter settings
Done: add a function to allow player(s) to decide if they want the grid to corospond with the NumPad (ie bOne would be botton
instead of top left)
Done: alter the Win function to determine a winner--does not determine cats games or 3-5-7 wins, cat command added in such events
ToDo: impliment a function to keep tracks of win's and loss's for x's and o's
ToDo: expand function to keep track of individual players' scores ( function will allow for players to alternate between x and o each game
ToDo: impliment a.i. (will be VERY last thing i do due to the comples switch-case's involved)
Done: alter place-piece to prevent player's from takeing eachother's squares
ToDo: come up with more ToDo's

if you have any suggestions lemme know

[edit] v1.0 done! you can now challenge yourself! and yourself! and any lonely friends who have nothing better to do! (like me!!(hint hint: i need friends 8-( )).

[edit] it has come to my attention that the .exe you can download does not load... i will work on the issue if oyu feel like trying it go ahead..

[edit] the issue is that the program requires the vc+= runtime env or something... I am going to begin developing (at least to create a useable .exe) with devc++ until i am familliar with the win32 api (so that my friends can assist in debugging without annoying downloads)

after dealing with that issue and realizeing that i have approximately 360800 games to code in order to create and impossible ai that will be last, my next step is to take it out of the console and (using the win32 api) add a GUI.. after becomeing familliar with the win32 api i will expand it further incorperating the direct x 9.0c SDK and than and only than will i bring it into the darkGDK ( i understand that darkGDK is much simpler to learn however the rout i'm takeing should provide more experience and understanding )

[edit] http://picasoe.iwarp.com has the working game as well as some stuff i made to help me learn (notes and sources of my own with ALOT of comments)

EYE R T3H +ick +ack +oe mester

Attachments

Login to view attachments
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 28th Aug 2009 08:39
please lock up this thread, i intened to create a thread for the game in the long run (i.e. one that covers teh entire developement)

EYE R T3H +ick +ack +oe mester

Login to post a reply

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