Ask coding questions

← Back to all posts
Is there a way to link two branches of code?
Justinwest27 (0)

In my CYOA, one of the paths starts with the main character finding a green light, if they do they go down the ufo path. If they don't, they go down another path that they could have gone down if they picked a different path at the beginning. So I have two paths that are exactly the same and to achieve this I've been just copying and paste the branch to that branch, but is there a better way to do this? Maybe with functions or something?

The lines I am talking about are 30-47 and 49-62
This is in python, if you can't see the python symbol by the name.

Comments
hotnewtop
Coder100 (16904)

Ok, so I think you are going to have to change how you do things.

def path_1():
  print("...")

def path_2():
  print("...")

def path_1_2():
  print("...")

def path_1_3():
  print("...")

def main():
  print("choose some path")
  # then you call it:
  path_2()

main()

This way allows you to rechoose paths and go all sorts of ways :D

Coder100 (16904)

btw, this is wrong:

It will always return True because python thinks it is:

if ufo_four_choice == "console" or ("the console" or "Console"):

instead, have:

if ufo_four_choice in "console", "the console", "Console":
Justinwest27 (0)

@Coder100 It's saying that that's invalid syntax.

Coder100 (16904)

Oh well, add parentheses around them ig
if ... in (..., ..., ...):
@Justinwest27

Coder100 (16904)

np!
mark as correct answer please @Justinwest27

Coder100 (16904)

Why are you tabs so weird lol

Justinwest27 (0)

@Coder100 What do you mean by tabs?

Justinwest27 (0)

@Coder100 oh, yeah. if it works it works i guess

Justinwest27 (0)

@Justinwest27 I have occasionally tried to make them not weird to no avail