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.
Line id indented, but the preceding one-line python statement statement does not expect a block?
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.
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.
-
- Newbie
- Posts: 11
- Joined: Mon May 31, 2021 12:09 pm
- Contact:
- 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?
if randaction = [attack]: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.
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.
-
- 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?
Here is the fight code screenshot:
Still need help.
Still need help.
Re: Line id indented, but the preceding one-line python statement statement does not expect a block?
There shouldn't be a colon after $ randaction = renpy.random.choice(["attack", "defend"]) and the blocks under it shouldn't be indented.
-
- 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?
Thanks, managed to get it working.
Who is online
Users browsing this forum: Exabot [Bot], fufuffiero, Sugar_and_rice