Computer Science Canada Connect Four error trap help needed as well as correct looping. |
Author: | Michael3176 [ Sun Dec 30, 2012 4:07 pm ] | ||||
Post subject: | Connect Four error trap help needed as well as correct looping. | ||||
Connect Four error trap help needed as well as correct looping and simplified a bit. What is the problem you are having? The game will not reset and start over when it is done, error traps are not working and seems to be over complicated. Here is the code, please help
Mod Edit: Pleas wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
|
Author: | Zren [ Sun Dec 30, 2012 7:29 pm ] |
Post subject: | RE:Connect Four error trap help needed as well as correct looping. |
What is suppose to happen, and what is exactly happening? To "replay" a section of code. You need to reset everything. Variables must be reset to whatever value they are required to be when the game starts. Another thing you probably overlooked is that you never actually clean up any of the buttons you created (probably because you were never taught to). Ask yourself what code is called the first time through, that isn't when you "restart" the game. Click the Main Menu button, the main menu button "disappears" and 3 other buttons are created. The Main Menu button is no longer visible (as you drew over it), but that does not mean it's not there. Try clicking where the button was. When creating a button (and other objects) you need to remember to destroy them (and free up the memory they take up). You can do this with GUI.Dispose(widgetID : int). There's an example of it's usage in the link. An alternate way to do what you wish would be to create all the buttons at the start, all of them disabled (Gui.Disable). You'd then enable then when you enter a screen, and disable them when you leave the screen. |
Author: | Michael3176 [ Mon Dec 31, 2012 9:59 am ] |
Post subject: | Re: Connect Four error trap help needed as well as correct looping. |
Yes you are correct about the buttons, but that is not my main concern, what is suppose to happen is that the game would reset whenever new game is pressed, but whenever i press new game it is simply continuing the game. I understand i need to reset variables, but i have no idea which ones to reset. Also my other problem is that the game does not exit to the mainMenu until after the turn of the winner. For ex: lets say player one gets four in a row, it will not exit until player two takes there turn, and vice verse |
Author: | Insectoid [ Mon Dec 31, 2012 11:05 am ] |
Post subject: | RE:Connect Four error trap help needed as well as correct looping. |
Quote: I understand i need to reset variables, but i have no idea which ones to reset.
You wrote the game, so you should know which ones need to be reset. It's probably safe to assume you'll have to reset most, if not all of them. You already have a setup procedure. Why not modify it so it resets the game whenever it's called? Unrelated, but the way your game is organized right now, after playing several games, you're going to have a userinput inside a mainmenu inside a userinput inside a mainmenu, etc. That's not ideal. Your program will end up consuming more and more RAM until there's no RAM left, and it crashes (though I think Turing will crash before that point). Instead of calling mainmenu at the end of userinput, you should keep everything inside mainmenu() in a loop, and just let userinput exit when it finishes. That way, when you finish a game, it quits the procedure and the original mainmenu resumes (currently, you'll get multiple mainmenus and userinputs running inside each other). |
Author: | Michael3176 [ Mon Dec 31, 2012 11:22 pm ] | ||
Post subject: | RE:Connect Four error trap help needed as well as correct looping. | ||
Ok thanks, i altered my program and now I do not know how to make counters stack on top of the other, for example if the user chooses i column twice, i do not know how to recognize that on Turing. I am trying make my connect four error traps and make it so the user cannot choose a full coloumn. What is the problem you are having? My error traps dont work properly and i dont know how to make counters stack on top of the other
|