-5

I'm trying to get this procedure to check whether the user lands on a treasure square and if they do they get gold. Also the treasure can only be landed on 3 times until it turns into a bandit, therefore after each time the player lands on it the tile's name changes, to T2, T3, B. Whenever I attempt to run my code an error appears saying can't assign to literal.

This is my code:

Mike Müller
  • 82,630
  • 20
  • 166
  • 161
  • 5
    can you post some code? This way no one can help you – Deepankar Bajpeyi Feb 09 '17 at 17:48
  • 1
    Please keep comments productive, obviously this is a user's first post, we all were beginners at one point in time, be kind and constructive – Nate Feb 09 '17 at 17:54
  • Note: http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values – jonrsharpe Feb 09 '17 at 17:54
  • 1
    @NathanDay we didn't all ignore the [help], or post *screenshots* of code... – jonrsharpe Feb 09 '17 at 17:54
  • @jonrsharpe I understand and agree with your point. However I doubt this is a case of abusing SO, but rather being novice and not knowing. If the user had an account for longer than today, it would be a different story – Nate Feb 09 '17 at 17:59
  • 1
    @NathanDay no, it wouldn't. Judge the *content*, not the *user*. – jonrsharpe Feb 09 '17 at 18:09

1 Answers1

1

You try to do this:

'T1' = 'T2'

which results ins:

    'T1' = 'T2'
               ^
SyntaxError: can't assign to literal

You cannot assign one string literal to another.

You could do something like this:

Grid[oldYpos][oldXpos] = 'T2'

A full if statement:

if Grid[oldYpos][oldXpos] == 'T1':
    Grid[oldYpos][oldXpos] = 'T2'
elif Grid[oldYpos][oldXpos] == 'T2':
    Grid[oldYpos][oldXpos] = 'T3'
elif Grid[oldYpos][oldXpos] = 'T3':
    Grid[oldYpos][oldXpos] = 'B'

Also better change:

if Grid[oldYpos][oldXpos] == 'T1' or 'T2'  or 'T3':

in:

if Grid[oldYpos][oldXpos] in ['T1', 'T2', 'T3']:
Mike Müller
  • 82,630
  • 20
  • 166
  • 161
  • Great that it helped. BTW, you can [accept](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) an answer if it solves your problem. – Mike Müller Feb 09 '17 at 18:55