Trying to create timer dependent on a variable

So I’ve come much further than my last post and am starting to get to the technical side of my game. Here’s a quick rundown of what I’m trying to do:

  • Have an ETA variable that increases either more or less depending on the output of another script (Check)
  • Have ETA displayed on text object by “minutes,” “hours,” and “days.” (Kind of check, know how to make text change)

Sounds pretty simple. The issue I’m having is with the second part. I can’t get the times to sync up right. I want the display to dynamically change throughout where either the ETA is lower or higher and can be changed at any time. I know how many frames are being used and I sort of have the math down, but all in all I can’t get it to do exactly what I want. I’ll post the code and a snapshot of the logic blocks.

(Haven’t started on days yet because hours won’t work.)


import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()

signal = scene.objects["Signal Switch"]["Signal Toggle"]
freq = scene.objects["Freq Dial"]["Freq"]
rfreq = scene.objects["Brains"]["RFreq"]
nopower = scene.objects["Power Switch"]["Power Toggle"]

minutes = scene.objects["eta_minutes_display"]
hours = scene.objects["eta_hours_display"]
days = scene.objects["eta_days_display"]

if nopower == False and signal == True and own["Energy"] > 0:
    if abs(rfreq - freq) <= 5:
        own["ETA"] += 3
        minutes.text = str(abs(own["ETA"] - 129600) % 60)
        hours.text = str(abs(own["ETA"] - 129600) % 24)
    
    elif  2 < abs(rfreq - freq) <= 10:
        own["ETA"] += 2
        minutes.text = str(abs(own["ETA"] - 259200) % 60)
        hours.text = str(abs(own["ETA"] - 129600) % 24)
    
    else:
        own["ETA"] += 1
        minutes.text = str(abs(own["ETA"] - 388800) % 60)
        hours.text = str(abs(own["ETA"] - 129600) % 24)
        
else:
    own["ETA"] += 1


Have the ETA script, set the variable directly each frame?

EtA = Distance / Speed

EtA should be calculated in frames?

Is the system setting the ETA a pathfinding algorithm?

I am having trouble understanding why energy and power etc have anything to do with ETA.

I would have locomotive and Ui seperate.

(player moves where ever)

Pathfinding gets route, and distance,

If there’s no power than a signal can’t be sent, thus making the eta only increment by 1. It’s not dependent on speed. Think of it of a timer left till the game is over

So I FINALLY figured it out. Here’s the script:


import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()

signal = scene.objects["Signal Switch"]["Signal Toggle"]
freq = scene.objects["Freq Dial"]["Freq"]
rfreq = scene.objects["Brains"]["RFreq"]
nopower = scene.objects["Power Switch"]["Power Toggle"]
intro = scene.objects["Player"]["Start"]

minutes = scene.objects["eta_minutes_display"]
hours = scene.objects["eta_hours_display"]
days = scene.objects["eta_days_display"]

mt = scene.objects["Minutes Text"]
ht = scene.objects["Hours Text"]
dt = scene.objects["Days Text"]

minutes.resolution = 12
hours.resolution = 12
days.resolution = 12

mt.resolution = 12
ht.resolution = 12
dt.resolution = 12

if intro == False: 
    if nopower == False:
        mt.color = [0.0, 0.0, 1.0, 1.0]
        ht.color = [0.0, 0.0, 1.0, 1.0]
        dt.color = [0.0, 0.0, 1.0, 1.0]
    
    elif nowpower == True:
        mt.color = [0.8, 0.8, 0.8, 0.0]
        ht.color = [0.8, 0.8, 0.8, 0.0]
        dt.color = [0.8, 0.8, 0.8, 0.0]
        
    if nopower == False and signal == True and own["Energy"] > 0:
        if abs(rfreq - freq) <= 5:
            own["ETA"] = own["ETA"] / 3
            own["ETA"] += 1

            days.text = str(int((own["ETA"] * -1) / 4320))
            if (int((own["ETA"] * -1) / 4320)) < 10:
                days.text = "0" + str(int((own["ETA"] * -1) / 4320))
                
            minutes.text = str(int((own["ETA"] * -1) / 3) % 60)
            if (int((own["ETA"] * -1) / 3) % 60) < 10:
                minutes.text = "0" + str(int((own["ETA"] * -1) / 3) % 60)
                
            hours.text = str(int((own["ETA"] * -1) / 180) % 24)
            if (int((own["ETA"] * -1) / 180) % 24) < 10:
                hours.text = "0" + str(int((own["ETA"] * -1) / 180) % 24)
                
            own["ETA"] = own["ETA"] * 3
                
        
        elif 5 < abs(rfreq - freq) <= 10:
            own["ETA"] = own["ETA"] / 1.5
            own["ETA"] += 1

            days.text = str(int((own["ETA"] * -1) / 4320))
            if (int((own["ETA"] * -1) / 4320)) < 10:
                days.text = "0" + str(int((own["ETA"] * -1) / 4320))
                
            minutes.text = str(int((own["ETA"] * -1) / 3) % 60)
            if (int((own["ETA"] * -1) / 3) % 60) < 10:
                minutes.text = "0" + str(int((own["ETA"] * -1) / 3) % 60)
                
            hours.text = str(int((own["ETA"] * -1) / 180) % 24)
            if (int((own["ETA"] * -1) / 180) % 24) < 10:
                hours.text = "0" + str(int((own["ETA"] * -1) / 180) % 24)
                
            own["ETA"] = own["ETA"] * 1.5


        else:
            own["ETA"] += 1

            days.text = str(int((own["ETA"] * -1) / 4320))
            if (int((own["ETA"] * -1) / 4320)) < 10:
                days.text = "0" + str(int((own["ETA"] * -1) / 4320))
                
            minutes.text = str(int((own["ETA"] * -1) / 3) % 60)
            if (int((own["ETA"] * -1) / 3) % 60) < 10:
                minutes.text = "0" + str(int((own["ETA"] * -1) / 3) % 60)
                
            hours.text = str(int((own["ETA"] * -1) / 180) % 24)
            if (int((own["ETA"] * -1) / 180) % 24) < 10:
                hours.text = "0" + str(int((own["ETA"] * -1) / 180) % 24)
                
                

    else:
        days.text = str((int(own["ETA"] * -1) / 4320))
        if int((own["ETA"] * -1) / 4320) < 10:
            days.text = "0" + str((int(own["ETA"] * -1) / 4320))
            
        minutes.text = str(int((own["ETA"] * -1) / 3) % 60)
        if (int((own["ETA"] * -1) / 3) % 60) < 10:
            minutes.text = "0" + str(int((own["ETA"] * -1) / 3) % 60)
            
        hours.text = str(int((own["ETA"] * -1) / 180) % 24)
        if (int((own["ETA"] * -1) / 180) % 24) < 10:
            hours.text = "0" + str(int((own["ETA"] * -1) / 180) % 24)

elif intro == True: 
    minutes.text = " "
    hours.text = "LOADING"
    days.text = " "
    mt.color = [0.8, 0.8, 0.8, 0.0]
    ht.color = [0.8, 0.8, 0.8, 0.0]
    dt.color = [0.8, 0.8, 0.8, 0.0]

Please note that most of this is fluff but the technical stuff took a while to figure out, though it looks very simple now.

If there are any questions, please ask!

You do have quite a lot of code replication there.

Why are you not using Python string format to create a formatted date?