-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Replace loop:
with while nextFrame():
in python
#2752
Comments
Your first forum-example is trumped up. His problem would not have changed by adding any sort of loop around his code, and he specifically states this. "While nextFrame()" would require the explanation of "frames" to happen in the Kithgard Dungeon, long before a knowledge of such things would be of any coding benefit. (as well as conditionals, etc. see below for when these currently appear) "A user expecting normal python" [prior knowledge] is not the target audience of CodeCombat... |
Let's look at the first linked example:
There are two ways to get that code correct:
or
When testing around I sometimes found that self.attack() needs nearly no time to execute and can lead to a infinitive loop. It doesn't seem to do this always.
No, the level could just tell the user that he has to write Apart from that the PS: Python is just discussing to add a |
Maybe you should try reading the post and not pulling code out of context to support your own theories: The following code results in an infinite loop, even though the selected enemy is clearly dead. The fix for his problem is NOT ANYTHING TO DO WITH THE LOOP, but fixing of the updating of the loss of enemy health. So that is most of your post. attack(something) --shouldn't-- be part of an infinite loop, ever . . . --shouldn't-- . . . temporary glitches not withstanding. Well, if you want to not explain things you just introduced then there is no need to change "loop" or explain that it isn't "real" python................. (but you are asking for it by "while nextFrame()" ?? what does that mean? at least "loop" does what it says and says what it does. It loops, If you want to complain about black-boxes then don't ever try to introduce python "for" loops, with out lots of explanation. This is not a "Teach pythonic python" site. This is a teach PROGRAMMING site, you choose the language to learn PROGRAMMING by using. You keep asking for the site to teach idiomatic python, PERIOD. |
I agree that adding a Maybe if we were going to do another campaign that moved a bit faster for older players, we would test out a |
I also get slightly bothered that Python is the default programming language but the lessons are not taught in a Pythonic way. Either way, seeing as the Python-to-JS compiler currently used in CodeCombat seems rather limited, it most likely isn't suitable for teaching the Pythonic way. I'm also not sure whether it wouldn't be too complicated for beginners, although I've heard good stories about students learning the Pythonic way before being exposed to C-family languages. Oh, sorry if I derailed the thread too much. 😛 Back on topic, |
We are just going to make |
I think hidden magic of that type is very confusing. A player who's code works when he writes |
So we'll handle that with responsive error messages or something. It's honestly not nearly as likely to come up as either 1) someone thinking that
|
@ChristianKleineidam I believe @nwinter means that any loop that does not perform any |
No, that would mess up a lot of code, like when you looping over a list/array of coins to find the most valuable one–your code would suddenly take one extra frame per coin. This is evil black magic to only apply when it's |
I see, makes sense. Though, in that case, you would most likely want to add the magical yield only to People moving the break condition to inside the loop is quite common. E.g.: n = 0
while True:
n++
# do something
if n > 3: break |
Ah yeah, that's a good extension of the heuristic! I think that anyone who knows how to use Really, the exercise would be to come up with breaking code that would actually be applied in a CodeCombat level–not necessarily the best way to do something, but one that at least sort of makes sense to some player doing it. Eventually I had come up with this crazy example: def commandFollowers():
# Iterate through friends between 1 and 2 times to either defend self or find a healer and defend it.
friends = self.findFriends()
friendIndex = 0
healer = None
timesIterated = 0
while True: # needs to not yield
friend = friends[friendIndex]
friendIndex += 1
if not healer and friend.type is 'paladin' and friend.canCast('heal', self):
healer = friend
self.command(friend, "cast", "heal", self)
elif friend is healer or friendIndex is len(friends):
if timesIterated or not healer:
break
else:
friendIndex = 0
timesIterated = 1
elif healer:
self.command(friend, "defend", healer)
else:
self.command(friend, "defend", self)
while True: # used to be simple loop, needs to yield
self.commandFollowers() # doesn't block But that's pretty out there... |
Yes, complex conditions that need to be tested inside the loop represent an use case. I believe the more common use case would be simply (ab)use
You're assuming that everyone will write code in the most conventional and optimally readable way. Given that the vast majority of CodeCombat players are beginner programmers, I believe that would not be the case. It is not uncommon for a learner to get addicted to certain language constructs right after discovering them (e.g. moving the break condition to a And yes, if I recall correctly, I used to be a |
We've finished doing this for the Course levels, intended to be used in classrooms, and will update the rest of the individual game levels sometime around when we change the way we do videos, most likely. |
The fact that python itself has no loop comment makes it very confusing for beginners when they learn in CodeCombat about
loop:
and then try to useloop:
in real cpython.The fact that
loop:
uses backround magic to wait for the next frame is very nonobvious to a beginner. A beginner will expect thatwhile True:
does the same thing asloop:
.The solution would be to add a new
nextFrame()
function that makes the magic explicit:Instead of
loop:
the standard could bewhile nextFrame():
.Why is this a problem? In January someone ask for help to debug an issue that comes from this error:
http://discourse.codecombat.com/t/python-while-loop-runs-infinitely/2407 nobody helped the poor guy. The error is non-obvious enough that forums users don't spot it.
User who are expecting normal python ask themselves whether this is really python when they see
loop
instead ofwhile
andfor
:http://discourse.codecombat.com/t/python-coding-question/3853/4
The text was updated successfully, but these errors were encountered: