Jump to content

How do I solve this?

Hallowenman

I know the very basics of python and have made very simple AIs and similar stuff. Right now I am trying to make a simple text based simulator that simulates airplanes (the systems, not flying). I want an input box where you type commands to do things, (and maybe a field of text that shows the airplanes current status but that will not happen right now). 

 

The problem I have is that I don't know how to make requirements. So for example: in order to run the command "start" (actually starting the engine of the plane) you must have turned on the electrical system (so "power on" or something similar must be "true" to allow you to run the command "start", and to make it more advanced I want to have multiple requirements to run some commands. I also want the very first thing (electricity) to have to be on to be able to do anything else, so if you don't enter the right command to turn the electrics on it loops back to the first input box so you have to enter it again instead of allowing you to skip it. I am using PyCharm, but with input commands you can only make one thing happen? So if you have an input box you can only have one 'if'? [ Example: "if "FUEL PUMP" in fuelppump.upper(): ]

 

I also want to be able to do things in whatever order as long as the requirements to do the action is fulfilled, so you can for example turn the fuel pump on before turning on the alternator as long as you have turned on power to be able to do these things. If anyone can help me that would be very appreciated!

CPU: Intel i5-9600k @ 4.9GHz Cooling Noctua NH-D14 Motherboard: ASUS ROG Strix Z390-F GAMING RAM: 32GB HyperX Fury DDR4 3200MHz GPU: EVGA GTX 1070 Ti SC PSU: Corsair TX650M SSD: Samsung 970 EVO Plus 250GB SSD (NVMe M.2) + Samsung 870 EVO SSD 2TB + Samsung 850 Evo 250GB HDD: 2TB Seagate Barracuda ST2000DM008 Case: SilverStone Redline Series RL06 OS: Windows 10 Pro 64-bit Display: Samsung 34" SJ55W Series S34J550WQU Keyboard: Corsair K95 Mouse: Logitech MX Master 2S Sound: SteelSeries Arctis 7 Wireless 2019 Black Joystick: Saitek Pro Flight X-56 Rhino Wheel: Thrustmaster T300 Ferrari Alcantara edition Pedals: Fanatec ClubSport Pedals V3 Shifter: Thrustmaster TH8A

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not very good at programming, first year with Java. But could you make some variables that contains just an int, and 0 is off and 1 is on, and when a person types the command it turns from 0 to 1 and then it will always check if all the required commands have been typed (aka being 1 and not 0) it will be able to start?

| Intel i5 4670k @ 4.3GHz | XFX RX 480 8 GB | Asus Z87i-Pro | 8.0 GB Kinston DDR3 | Samsung Evo 120GB SSD |

Link to comment
Share on other sites

Link to post
Share on other sites

treat each part as an object with various characteristics like STATE ( OFF, ON , CHANGING - with maybe progress meter) , and for each of them have a list of dependencies. 

Ex  fuel pump depends on object called electrical system having its state set to ON

Give each object an unique ID , a name and the state which could be a number ( 0 for off , 1..99 for progress, 100 for on) , and the list of what depends on.

 

so for example

uid, name, state , depends on

1, electricity, 100,  " "

[..]

20, fuel pump , 0 ,  "1,5,12" 

 

etc etc

You can just write a function that goes looks at objects 1, 5 and 12 in the array and checks their state and if all are 100, then you can set the state of fuel pump to on, or launch some kind of timer or function running in a separate thread  (or your code could have a loop doing stuff in background while waiting for text commands) which gradually raises the progress until it's 100 (on), if you want to simulate things taking time to turn on

 

Link to comment
Share on other sites

Link to post
Share on other sites

29 minutes ago, mariushm said:

You can just write a function that goes looks at objects 1, 5 and 12 in the array and checks their state and if all are 100, then you can set the state of fuel pump to on,

 

What would that look like for someone with basic python experience? It looks like this could work just fine for me, but I'm not quite sure how to write a function like that

CPU: Intel i5-9600k @ 4.9GHz Cooling Noctua NH-D14 Motherboard: ASUS ROG Strix Z390-F GAMING RAM: 32GB HyperX Fury DDR4 3200MHz GPU: EVGA GTX 1070 Ti SC PSU: Corsair TX650M SSD: Samsung 970 EVO Plus 250GB SSD (NVMe M.2) + Samsung 870 EVO SSD 2TB + Samsung 850 Evo 250GB HDD: 2TB Seagate Barracuda ST2000DM008 Case: SilverStone Redline Series RL06 OS: Windows 10 Pro 64-bit Display: Samsung 34" SJ55W Series S34J550WQU Keyboard: Corsair K95 Mouse: Logitech MX Master 2S Sound: SteelSeries Arctis 7 Wireless 2019 Black Joystick: Saitek Pro Flight X-56 Rhino Wheel: Thrustmaster T300 Ferrari Alcantara edition Pedals: Fanatec ClubSport Pedals V3 Shifter: Thrustmaster TH8A

Link to comment
Share on other sites

Link to post
Share on other sites

 

I would draw a flow chart (at bottom)

electric = 0
fuel = 0
engine = 0
def startEngine():
  if electric == 0:
    print("electric must be turned on");
  elif fuel == 0:
    print("Fuel must be engauged");
  else:
    print ('engine started')
  
def commands(cmd):
  if cmd == "start":
    startEngine();
  elif cmd == "elc tog":
    if electric == 0:
      global electric
      electric = 1
      print("electric toggled on")
    else:
      global electric
      electric = 0
      print("electric toggled off")
  elif cmd == "fuel tog":
    if fuel == 0:
      global fuel
      fuel = 1
      print("fuel toggled on")
    else:
      global fuel
      fuel = 0
      print("fuel toggled off")
  if cmd == "exit":
    quit()
    

#main
while True:
  print("Please command")
  commands(input(">"))
    

output

Please command
> start
electric must be turned on
Please command
> elc tog
electric toggled on
Please command
> start
Fuel must be engauged
Please command
> fuel tog
fuel toggled on
Please command
> start
engine started
Please command
> 

You will need to add it far more checks like not being able to turn off electric or fuel while the engine is running. 

Screenshot from 2016-11-30 12-27-05.png

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, vorticalbox said:

 

I would draw a flow chart (at bottom)


electric = 0
fuel = 0
engine = 0
def startEngine():
  if electric == 0:
    print("electric must be turned on");
  elif fuel == 0:
    print("Fuel must be engauged");
  else:
    print ('engine started')
  
def commands(cmd):
  if cmd == "start":
    startEngine();
  elif cmd == "elc tog":
    if electric == 0:
      global electric
      electric = 1
      print("electric toggled on")
    else:
      global electric
      electric = 0
      print("electric toggled off")
  elif cmd == "fuel tog":
    if fuel == 0:
      global fuel
      fuel = 1
      print("fuel toggled on")
    else:
      global fuel
      fuel = 0
      print("fuel toggled off")
  if cmd == "exit":
    quit()
    

#main
while True:
  print("Please command")
  commands(input(">"))
    

output


Please command
> start
electric must be turned on
Please command
> elc tog
electric toggled on
Please command
> start
Fuel must be engauged
Please command
> fuel tog
fuel toggled on
Please command
> start
engine started
Please command
> 

You will need to add it far more checks like not being able to turn off electric or fuel while the engine is running. 

Screenshot from 2016-11-30 12-27-05.png

I put that into PyCharm to run the code and that gives Syntax Warnings,

 

"SyntaxWarning: name 'electric' is used prior to global declaration
>  global electric"

 

"SyntaxWarning: name 'electric' is assigned to before global declaration
  global electric"

 

"SyntaxWarning: name 'fuel' is used prior to global declaration
  global fuel"

 

"SyntaxWarning: name 'fuel' is assigned to before global declaration
  global fuel"

CPU: Intel i5-9600k @ 4.9GHz Cooling Noctua NH-D14 Motherboard: ASUS ROG Strix Z390-F GAMING RAM: 32GB HyperX Fury DDR4 3200MHz GPU: EVGA GTX 1070 Ti SC PSU: Corsair TX650M SSD: Samsung 970 EVO Plus 250GB SSD (NVMe M.2) + Samsung 870 EVO SSD 2TB + Samsung 850 Evo 250GB HDD: 2TB Seagate Barracuda ST2000DM008 Case: SilverStone Redline Series RL06 OS: Windows 10 Pro 64-bit Display: Samsung 34" SJ55W Series S34J550WQU Keyboard: Corsair K95 Mouse: Logitech MX Master 2S Sound: SteelSeries Arctis 7 Wireless 2019 Black Joystick: Saitek Pro Flight X-56 Rhino Wheel: Thrustmaster T300 Ferrari Alcantara edition Pedals: Fanatec ClubSport Pedals V3 Shifter: Thrustmaster TH8A

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, Hallowenman said:

I put that into PyCharm to run the code and that gives Syntax Warnings,

 

"SyntaxWarning: name 'electric' is used prior to global declaration
>  global electric"

 

"SyntaxWarning: name 'electric' is assigned to before global declaration
  global electric"

 

"SyntaxWarning: name 'fuel' is used prior to global declaration
  global fuel"

 

"SyntaxWarning: name 'fuel' is assigned to before global declaration
  global fuel"

 

move the global too the top and then set them under it. really you should use a class for this but as you said you were new I didn't want to make it too complicated.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×