Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function Not Working
#1
Exclamation 
I am making a text game. And what I am doing is using another python file as a module in the Main python file(Mod File). And The main file calls The Input_Main_Colony() function and I know it's going there because if I put a print("Passed") in the if statement it will print.But it won't run the Cheats function. And the base game bases what it does next from return codes. 0 means nothing happened 1 means something happened. But it won't pass either codes. It seems the program tries to run Cheat but it errors out.
(If you need me to explain something from my code ask me please)
def Input_Main_Colony(Input, ColonyVarbles):
    if Input == "cheat" or Input == "cheats":
        return Cheat(ColonyVarbles)
    return 0

def Cheat(Varables):
    C("cls")
    print("You can change the amount of a resource. Which one?")
    print("People\nMaterials\nPeople\nWood\nCASE SENSITIVE")
    ThingChange = input(": ")
    C("cls")
    print("How much of this resource do you want?")
    Amount = int(input(": "))
    Varables[ThingChange] = Amount
    return 1
try:
        Return = Mod.Input_Main_Colony(Input, Colony_Varables)
        time.sleep(2)
    except:
        pass
^^^^^This is how I'm running the Input_Mian_Colony() funtion from the main file
Reply
#2
what does function C look like?
Place a print statement print("Returned") after line 7 to see if flow is returned
Reply
#3
(Jul-19-2022, 02:33 AM)Larz60+ Wrote: what does function C look like?
Place a print statement print("Returned") after line 7 to see if flow is returned
It's not a function its a varable (C = os.system)
And the print("Returned") doesn't show
Reply
#4
C is just another name for the os.system function. It is generally a bad idea to use single letter names for things, as they don't convey meaning. That lack of meaning makes code harder to read.
buran likes this post
Reply
#5
remove the bare try/except and see what the error is
we don't know what Input and Colony_Varables used when calling Mod.Input_Main_Colony are.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Jul-19-2022, 05:25 AM)ndc85430 Wrote: C is just another name for the os.system function. It is generally a bad idea to use single letter names for things, as they don't convey meaning. That lack of meaning makes code harder to read.
Noted
Reply
#7
(Jul-19-2022, 05:42 AM)buran Wrote: remove the bare try/except and see what the error is
we don't know what Input and Colony_Varables used when calling Mod.Input_Main_Colony are.
I don't know why I didn't think to remove the try/except but i figured out what it was. The C = os.system had ("cls") in the function/varabale so the c("cls") what really os.system("cls")("cls")
And the Input was just Input = str.lower(input(": ")
and the Colony_Varables was a dictionary
Reply
#8
str.lower() is a method. Though you can call a method this way, classname.methodname(instance), it is unusual. The common way is like this:
Input = input(": ").lower()
This corresponds to instance.methodname().

Since you are starting out learning Python, now is the best time to develop good habits. I find your code difficult to read because you are not using conventions used by most Python programmers. You can learn about these conventions here:

https://pep8.org/
ndc85430 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked kindly support with this dropna function not working gheevarpaulosejobs 2 681 Jul-24-2023, 03:41 PM
Last Post: deanhystad
  try function working on PC but not raspberry pi AnotherSam 1 1,545 Oct-11-2021, 04:51 AM
Last Post: bowlofred
  Input() function not working in VS Code darpInd 7 13,359 Feb-17-2020, 03:28 PM
Last Post: snippsat
  Unrelated new function causing existing working function to fail Nick_G 2 2,275 Jan-27-2020, 07:21 PM
Last Post: Nick_G
  User Defined function not working Raj_Kumar 4 3,024 Dec-17-2019, 12:44 PM
Last Post: buran
  Function not working eglaud 0 1,649 Oct-24-2019, 03:30 PM
Last Post: eglaud
  Invoking function in if else statement, not working! ibaad1406 13 5,648 May-30-2019, 09:05 PM
Last Post: ibaad1406
  function not working tryingtolearnpython 2 2,970 Jul-23-2018, 02:54 AM
Last Post: tryingtolearnpython
  function for SQLite query not working pythonNoob 1 2,803 May-16-2018, 05:21 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020