#๐ game randomly triggers meltdown?
13 messages ยท Page 1 of 1 (latest)
@solemn crag
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
ok so my game randomly triggers meltdowns idk what it is
Hey @solemn crag!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
import tkinter as tk
import time
import random as rnd
from tkinter.ttk import *
window = tk.Tk()
running = 0
ltwarn = 0
htwarn = 0
endgame = 0
cp1status = 0
cp1 = 0
cp2status = 0
cp2 = 0
def Start():
global temp, reactorstate, running, templb, coolantWin, cp1status, coolantStatRep1, c1label, c1p4, c1p3, c1p2, c1p1, c1p0, cp1, c2label, c2p4, c2p3, c2p2, c2p1, c2p1, c2p0, cp2, coolantStatRep2, cp2status, c1pd, c2pd
print("Started")
temp = 2000
reactorstate = 1
running = 1
cp1status = 10
cp2status = 10
#temperature label
templb = tk.Label(window, text= temp)
templb.pack()
#coolant control panel
coolantWin = tk.Tk()
coolantWin.title("Coolant Control")
coolantWin.geometry("1000x300")
#pump1
coolantStatRep1 = tk.Label(coolantWin, text = "Ready for input")
coolantStatRep1.grid(row=1, column = 0, pady = 2, padx = 2)
c1label = tk.Label(coolantWin, text = "Pump 1")
c1label.grid (row = 0, column = 0, pady = 2, padx = 2)
#power settings
c1p4 = tk.Button(coolantWin, text = "Max Power", fg = "Red", command = lambda: setPower("cp1", 4))
c1p4.grid (row = 0, column = 1, pady = 2, padx = 2)
#power3
c1p3 = tk.Button(coolantWin, text = "Power 3", command = lambda: setPower("cp1", 3))
c1p3.grid (row = 1, column = 1, pady = 2, padx = 2)
#power2
c1p2 = tk.Button(coolantWin, text = "Power 2", command = lambda: setPower("cp1", 2))
c1p2.grid (row = 2, column = 1, pady = 2, padx = 2)
#power1
c1p1 = tk.Button(coolantWin, text = "Power 1", command = lambda: setPower("cp1", 1))
c1p1.grid (row = 3, column = 1, pady = 2, padx = 2)
#power0
c1p0 = tk.Button(coolantWin, text = "Shutoff", command = lambda: setPower("cp1", 0))
c1p0.grid (row = 4, column = 1, pady = 2, padx = 2)
#power display
c1pd = tk.Label(coolantWin, text = "awaiting input")
c1pd.grid (row = 2, column = 0, pady = 2, padx = 2)
````
coolantStatRep2 = tk.Label(coolantWin, text = "Ready for input")
coolantStatRep2.grid(row=1, column = 2, pady = 2, padx = 2)
c2label = tk.Label(coolantWin, text = "Pump 2")
c2label.grid(row = 0, column = 2, pady = 2, padx = 2)
#power settings
#power4
c2p4 = tk.Button(coolantWin, text = "Max Power", fg = "Red", command = lambda: setPower("cp2", 4))
c2p4.grid( row = 0, column = 3, pady = 2, padx = 2)
#power3
c2p3 = tk.Button(coolantWin, text = "Power 3", command = lambda: setPower("cp2", 3))
c2p3.grid( row = 1, column = 3, pady = 2, padx = 2)
#power2
c2p2 = tk.Button(coolantWin, text = "Power 2", command = lambda: setPower("cp2", 2))
c2p2.grid( row = 2, column = 3, pady = 2, padx = 2)
#power1
c2p1 = tk.Button(coolantWin, text = "Power 1", command = lambda: setPower("cp2", 1))
c2p1.grid( row = 3, column = 3, pady = 2, padx = 2)
#power0
c2p0 = tk.Button(coolantWin, text = "Shutoff", command = lambda: setPower("cp2", 0))
c2p0.grid( row = 4, column = 3, pady = 2, padx = 2)
c2pd = tk.Label(coolantWin, text = "awaiting input")
c2pd.grid (row = 2, column = 2, pady = 2, padx = 2)
#emergency coolant
#emc1
emc1 = tk.Button(coolantWin, text = "emergency coolant 1", command = lambda: emCool(emc1),bg = "green")
emc1.grid (row = 0, column = 4, pady = 2, padx = 2)
#emc2
emc2 = tk.Button(coolantWin, text = "emergency coolant 2", command = lambda: emCool(emc2),bg = "green")
emc2.grid (row = 1, column = 4, pady = 2, padx = 2)
#emc3
emc3 = tk.Button(coolantWin, text = "emergency coolant 3", command = lambda: emCool(emc3),bg = "green")
emc3.grid (row = 2, column = 4, pady = 2, padx = 2)
#print stuff and start
print("running")
print("temperature:",temp)
print("reactorstate:",reactorstate)
print ("running")
startbt.destroy()
window.update()
run()
def setPower(what,level):
global cp1, cp2
print(what,"to ",level)
if what == "cp1":
cp1 = level
if what == "cp2":
cp2 = level
def run():
global temp, reactorstate, coolant, running, ltwarn, lowtemp, htwarn, hightemp, coolantStatRep1, templb, cp1status, cp1, cp2status, cp2, coolantStatRep2, c1pd
#low temperature warning
if temp <= 1500 and ltwarn == 0:
lowtemp = tk.Label(window,text = "Low temp!!!", bg="Blue")
lowtemp.pack()
ltwarn = 1
if temp > 1500 and ltwarn == 1:
lowtemp.destroy()
ltwarn = 0
#high temperature warning
if temp >= 2500 and htwarn == 0:
hightemp = tk.Label(window,text = "High temp!!!", bg = "Red")
hightemp.pack()
htwarn = 1
if temp < 2500 and htwarn == 1:
hightemp.destroy()
htwarn = 0
#reactor stall
if isStall(temp):
stall()
#reactor meltdown
if isMeltdown(temp):
meltdown()
#coolant display
#pump1
if cp1status >= 5:
coolantStatRep1.config(text ="stable",bg = "Green")
elif cp1status >= 2:
coolantStatRep1.config(text ="damaged",bg = "Yellow")
elif cp1status > 0:
coolantStatRep1.config(text ="very damaged",bg = "Orange")
else:
coolantStatRep1.config(text ="broken",bg = "Red")
c1pd.config(text = "Power: " +str(cp1))
#pump2
if cp2status >= 5:
coolantStatRep2.config(text ="stable",bg = "Green")
elif cp1status >= 2:
coolantStatRep2.config(text ="damaged",bg = "Yellow")
elif cp1status > 0:
coolantStatRep2.config(text ="very damaged",bg = "Orange")
else:
coolantStatRep2.config(text ="broken",bg = "Red")
c2pd.config(text = "Power: " +str(cp2))````
#reactorstate calculation
reactorstate = 1.03
if cp1 != 0:
reactorstate = reactorstate - (cp1+1)/200
if cp2 != 0:
reactorstate = reactorstate - (cp2+1)/200
#print
print("next row")
print ("reactorstate ",reactorstate)
#temperature
temp = temp * reactorstate
temp = int(temp)
templb.config(text = temp)
#loop
if endgame == 0 and running == 1:
window.after(1000, run)
elif endgame == 1:
print ("game end")
else:
print ("error")
def stall():
global endgame, stalllb
endgame = 1
print ("reactor stalled!")
stalllb = tk.Label(window, text = "Reactor stalled! Game over")
stalllb.pack()
def meltdown():
global endgame, meltlb
endgame = 1
print ("reactor meltdown!")
meltlb = tk.Label(window, text = "Reactor Meltdown! Game over")
meltlb.pack()
def SetPower(what, pwr):
what = pwr
print (what," ",pwr)
def isMeltdown(curTemp):
limit = 0
if curTemp >= 2700:
limit=30
elif curTemp >= 3300:
limit= 70
return rnd.randint(0,100) <= limit
def isStall(curTemp):
limit = 0
if curTemp <= 1000:
limit=30
elif curTemp <= 700:
limit= 70
return rnd.randint(0,100) <= limit
def emCool(pump):
global temp
pump.config(bg ="red", command = None)
temp = temp - 300
startbt = tk.Button(window, text="Start", command= Start)
startbt.pack()
What are you observing, and how is it different from what you're expecting?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.