Line id indented, but the preceding one-line python statement statement does not expect a block?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
frytkosz-555
Newbie
Posts: 11
Joined: Mon May 31, 2021 12:09 pm
Contact:

Line id indented, but the preceding one-line python statement statement does not expect a block?

#1 Post by frytkosz-555 »

I was coding a fight for my game and it worked preety well but the enemy could only do one thing so I tried out a renpy.random.choice for it to randomly swap between
attack and defend and some other options, here is my code:

show screen battle_stats_screen

while (Android_hp > 0) and (Dextra_hp > 0):

menu:
"Melee attack 2-5":
$ Melee_damage = renpy.random.randint(2, 5)
$ Android_hp -= Melee_damage
Android "K-y-aaa!!!11 (damage dealt - [Melee_damage]hp)"

"Use Medkit (got [Medkits_left] medkits left)" if Medkits_left > 0:
$ Dextra_hp = min(Dextra_hp+5, Dextra_max_hp)
$ Medkits_left -= 1
Dextra "Medkit used (restore 5hp)"

"Fire a supercharged shot 6-10(got [Supercharged_shots_left] supercharged shots left)":
$ Supercharged_shot_damage = renpy.random.randint(6, 10)
$ Android_hp -= Supercharged_shot_damage
$ Supercharged_shots_left -= 1
Android "Ufff (damage delt -[Supercharged_shot_damage]hp)"

$ randaction = renpy.random.choice(["attack", "defend"])
if randaction = [attack]:
show android_battle1_2
$ Android_damage = renpy.random.randint(3, 6)
$ Dextra_hp -= Android_damage
Android "BangBang! {i}*Android hits you*{/i} (damage dealt - [Android_damage]hp)"
hide android_battle1_2
if randaction = [defend]:
show android_battle1_3
"android defends"

hide screen battle_stats_screen



The error is refering to line: if randaction = ["attack"]

PLS help, Thanks.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Line id indented, but the preceding one-line python statement statement does not expect a block?

#2 Post by Per K Grok »

frytkosz-555 wrote: Mon May 31, 2021 12:18 pm I was coding a fight for my game and it worked preety well but the enemy could only do one thing so I tried out a renpy.random.choice for it to randomly swap between
attack and defend and some other options, here is my code:

show screen battle_stats_screen

while (Android_hp > 0) and (Dextra_hp > 0):

menu:
"Melee attack 2-5":
$ Melee_damage = renpy.random.randint(2, 5)
$ Android_hp -= Melee_damage
Android "K-y-aaa!!!11 (damage dealt - [Melee_damage]hp)"

"Use Medkit (got [Medkits_left] medkits left)" if Medkits_left > 0:
$ Dextra_hp = min(Dextra_hp+5, Dextra_max_hp)
$ Medkits_left -= 1
Dextra "Medkit used (restore 5hp)"

"Fire a supercharged shot 6-10(got [Supercharged_shots_left] supercharged shots left)":
$ Supercharged_shot_damage = renpy.random.randint(6, 10)
$ Android_hp -= Supercharged_shot_damage
$ Supercharged_shots_left -= 1
Android "Ufff (damage delt -[Supercharged_shot_damage]hp)"

$ randaction = renpy.random.choice(["attack", "defend"])
if randaction = [attack]:
show android_battle1_2
$ Android_damage = renpy.random.randint(3, 6)
$ Dextra_hp -= Android_damage
Android "BangBang! {i}*Android hits you*{/i} (damage dealt - [Android_damage]hp)"
hide android_battle1_2
if randaction = [defend]:
show android_battle1_3
"android defends"

hide screen battle_stats_screen



The error is refering to line: if randaction = ["attack"]

PLS help, Thanks.
if randaction = [attack]:

should be

if randaction == "attack":

'=' is used to set a variable to a value
'==' is used to compare a variable with a value


The same thing with ' if randaction = [defend]: '


You should have used the code tags around your code, then we could have seen the indentation you have used.

I guess you have indented the line 'if randaction = [attack]:'
but the line before that, ' $ randaction = renpy.random.choice(["attack", "defend"]) ', is not a line that starts a block, so the line following that should not be indented.

frytkosz-555
Newbie
Posts: 11
Joined: Mon May 31, 2021 12:09 pm
Contact:

Re: Line id indented, but the preceding one-line python statement statement does not expect a block?

#3 Post by frytkosz-555 »

Here is the fight code screenshot:

Image

Still need help.

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Line id indented, but the preceding one-line python statement statement does not expect a block?

#4 Post by philat »

There shouldn't be a colon after $ randaction = renpy.random.choice(["attack", "defend"]) and the blocks under it shouldn't be indented.


Post Reply

Who is online

Users browsing this forum: Exabot [Bot], fufuffiero, Sugar_and_rice