Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Called Functions Not Working
#1
So I am trying to do Five Nights at Freddy's in real life and I need a calculator to see how much power we have left. But I keep running into a problem. I defined a few functions (Using the lights, closing the doors), and called them, but for some reason when I run the script and try to use them it does not work. It's not an error. I will type the function 'l' when running the code and it gives me: <function l at *Random numbers, letters, and symbols*

import time
power = 100 

power_calc = input("l is left door, r is right door, and f is flashlight. Awaiting Input:")
if len(power_calc) < 0:
        print("empty")

#this is for l
def l():
        if power_calc is 1:
                time_1 = time
def ll():
        if power_calc is ll:
            time_2 = time
            time_total_1 = int(time_1) - int(time_2)
            power - time_total_1  

#this is for r
def r():
        if power_calc is r:
                time_3 = time

def rr():
        if power_calc is rr:
            time_4 = time
            time_total_2 = int(time_3) - int(time_4)
            power - time_total_2

#this is for f
def f():
        power - 2

l()
ll()
r()
rr()
f()

if power == 0:
        print("Game Over")

And this is what it will give me when I run it:

Output:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> RESTART: C:\Users\Steven & Alisha\AppData\Local\Programs\Python\Python37-32\FNaF power calculator.py l is left door, r is right door, and f is flashlight. Awaiting Input: >>> l <function l at 0x033A3C90> >>>
Quote
#2
When calling a function, you need to add parenthesis at the end - l(). Doing this - l will call the function name and it's memory location

I don't know what is up with the output there, but it is showing a new line, the program is no longer running
Age Doesn't Matter, Your Passion Does
- Shreya Jain
Quote
#3
power_calc is a string, print(type(power_calc)). You are comparing it to an integer, which will never be True.
Quote
#4
You really need to review functions, especially how to pass values with parameters and return to assignments with the return statement. See the functions tutorial link in my signature, below.

Also, time is a module. Doing time_1 = time just gives you a new name for the module, which goes away after the function ends. If you want to get the current time using the time module's time function, you want time_1 = time.time().
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do you add the results together each time a function is called? Exsul 10 419 Aug-09-2019, 09:18 PM
Last Post: ichabod801
  Best method: Python script called from another app, package as complete executable ironfelix717 2 121 Jul-24-2019, 07:39 AM
Last Post: DeaD_EyE
  Getting error when called through instance method aankrose 2 292 Mar-02-2019, 07:19 PM
Last Post: aankrose
  Time multiple functions within functions Cortessizzz 4 449 Jan-09-2019, 04:15 PM
Last Post: Cortessizzz
  Working on nested functions boxerboy1168 2 407 Dec-28-2018, 07:54 AM
Last Post: Gribouillis
  Have function reject bad argument when argument is called by another function? jobroinc 5 722 Jul-21-2018, 02:09 AM
Last Post: jobroinc
  setting parameters for functions and nested functions mepyyeti 5 933 Feb-25-2018, 06:42 PM
Last Post: snippsat
  Script crashes when called from a second script cryomick 2 945 Oct-31-2017, 01:27 PM
Last Post: cryomick
  Built in Functions not working mhoneycutt83 4 1,852 Jul-28-2017, 07:39 AM
Last Post: DeaD_EyE
  How is space of variables/functions/objects... called? j.crater 4 1,796 Dec-19-2016, 12:24 PM
Last Post: j.crater

Forum Jump:


Users browsing this thread: 1 Guest(s)