Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added restart button and fixed some bugs #18

Merged
merged 16 commits into from
Nov 2, 2016

Conversation

msohcw
Copy link
Contributor

@msohcw msohcw commented Oct 6, 2016

Hi Colin. I'm in your 61A discussion. I noticed that you made this and had Restart button as an active issue so I added the functionality. Also fixed a bug with clearInterval(gui.interval), needed to bind this to the function call otherwise this would be the global window.

Copy link
Owner

@colinschoen colinschoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Thanks! I'll review tomorrow.

@msohcw
Copy link
Contributor Author

msohcw commented Oct 6, 2016

Didn't test enough. Fixed the gui_ants.py so the hooks get added every time a game starts. Also standardised GUI.update to use this instead of the global gui.

@colinschoen
Copy link
Owner

colinschoen commented Oct 7, 2016

Are you getting an AttributeError after startGame and on getState?

File "gui.py", line 273, in do_POST
response = action(data)
File "gui.py", line 117, in getState
return self.state.getState()
AttributeError: 'GUI' object has no attribute 'state'

@msohcw
Copy link
Contributor Author

msohcw commented Oct 7, 2016

I saw that, but it was a heisenbug. The only reliable way I had to replicate it was to start gui.py, start a game, kill gui.py and then start gui.py again. The leftover windows sending POST requests when the Python server doesn't have a state yet causes the error. I could add a clause to the do_POST function. Is that the bug you're seeing though? Or does it error straight away on starting gui.py?

@colinschoen
Copy link
Owner

It is happening straight away when starting gui.py

@msohcw
Copy link
Contributor Author

msohcw commented Oct 7, 2016

Do you have multiple Ants Web Viewer windows open?

@colinschoen
Copy link
Owner

Nope, only one window. I can do some debugging later today too.

@msohcw
Copy link
Contributor Author

msohcw commented Oct 7, 2016

Might be a timing thing. I reordered it so that the GUI calls cleanState in __init__ (as it previously was) and so that it calls cleanState before reload(ants.py) which might be taking up time.

@colinschoen
Copy link
Owner

What browser/OS are you on. I am running a fresh copy of your fork of the GUI and the project and not able to make any state calls. You have everything pushed right?

NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:8000/ajax/fetch/state'.

@msohcw
Copy link
Contributor Author

msohcw commented Oct 11, 2016

That's very odd. I git clone'd my repo, then copied in ants/*.py except gui.py and state.py, and it works fine. I'm on Ubuntu, tested against Chrome/Firefox. Do you need me to upload the rest of the .py s?

@colinschoen
Copy link
Owner

colinschoen commented Oct 11, 2016

Can you shoot me an archive of your proj directory with the updated GUI to cschoen [at] berkeley.edu. I'll see if I can find any oddities.

@msohcw
Copy link
Contributor Author

msohcw commented Oct 11, 2016

Done. I tar'd up a working copy with the project files and updated gui.py and assets/app.js.

@msohcw
Copy link
Contributor Author

msohcw commented Oct 27, 2016

Hmm I think I managed to replicate the error. It seems to be a small timing bug where the player clicks 'Start game', and a POST request is made to the server to start and to get the state, but the server isn't ready yet and causes the request to fail. I added an initialised flag so that it keeps trying to get the state when it is unitialised and only throws an error when there's a network error despite it having been previously initialised.

@colinschoen
Copy link
Owner

setTimeout(gui.get_gameState(async), 500)

Can't find variable async line 111.

@colinschoen
Copy link
Owner

Excellent work! Thank you.

@colinschoen colinschoen merged commit 19ffe1d into colinschoen:master Nov 2, 2016
@colinschoen colinschoen mentioned this pull request Nov 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants