Ask coding questions

← Back to all posts
Solved: glitch .....Text Adventure (Python) code works but breaks waayyy too easily???
tech4teachers (1)

SOLVED....looks like this was an autoformatting error, took all of the code and exported it as a zip, opened it in Sublime, added a new print output to line 333 and resaved it/copied/pasted back into ...and it WORKED.... no more unindent error!

Also played around with changing Python 3's use of >input< and using the supposedly still valid >raw_input< compatible with in Sublime and my terminal ....but not in

Old post below>>>>
Need help, I am doing and introductory summer class teaching basic coding concepts and our final project is this Python 3 text adventure "proto-game" that the kids can then adapt and run with as their creativity and comfort with Python expands.
Here is the really weird thing...the code works ....but it breaks ridiculously easily if I try to add an extra >>>print("this is just for debugging")<<< line of code at line 333 before the >>>prompt()<<< **see picture of the [pyflakes] error below...the line I am adding is not necessary, but bizarrely breaks the whole program waayyy too easily.

It's weird that adding anything ...even if I delete it....even if I completely retype lines 329---through---335 from scratch....once something else has been added to line 333 an "unindent" error plagues the code permanently in that location unless I completely crtl or command Z to undo all the way back to the original working original.

I hand coded this entire thing, got it working as a decent template for the kids to replicate themselves ( also from scratch...I am not a copy-paste teacher) and then explore further.

The original code works....I just can't figure out why it breaks sooooo easily.

I have been going back line for line, re-indenting everything, even deleting all comments to get down to 'pure' uncommented code.... but once you mess with that spot it breaks....and refuses to debug matter what I do.

Could it be the mixture of comments using """ and ## or # ?
Could it be some tab or errant spacebar indent elsewhere I can't find?
Could it be just a structural issue with the order and sequence of the functions, when they are created vs when they are called?

Can anyone point us in a useful direction to fix this....even if it means a complete rewrite??

Answered by Edgod (80) [earned 5 cycles]
View Answer
Edgod (80)

This is definitely a strange problem, but it's most likely the cause of a update/bug. Indentations before were actual tabs, but now an amount of spaces is used as indentations. When you add a new line, it uses spaces to indent instead of tabs the rest of the code has. That's why you're given that certain IndentationError: unindent does not match any outer indentation level

What you can do Find and Replace to replace the old indentation (copy and paste it on the Find box) with a number of spaces (look at indent size in settings to know how many spaces to put). The "new" indentation might be considered a bug though, I don't know if the team will switch back to actual tabs.

tech4teachers (1)

@Edgod ...thanks
Hrmm...that sounds like a distinct possibility. I had that problem with Sublime and found that handled the same code that erred out in my local command line with ease...but I have noticed some shifts and changes over the years that were equally hard to diagnose. I might do a quick double/triple/quadruple check in PyCharm.... Thanks for understanding Edgod, people forget it's hard on teachers to juggle all that we do and then troubleshoot things that should work and are only just frustrating the kids to the point they give up and walk away from the awesome potential of the profession. People ask me how to get kids 'interested' STEM and I tell them bluntly "get in here and help more".

tech4teachers (1)

@Edgod ....SOLVED.... I just amended the original post...took it into sublime and it worked just fine....reimported into now it works!!!

Ridiculous waste of time, but glad it works.