The Farmer Was Replaced

The Farmer Was Replaced

Function not working
I read patch, than I know functions has been changed. But now I try use "def" in other window with import, but its not working. I try "import window_name" and "from window_name import * / function".
< >
Showing 1-3 of 3 comments
it is working for me when I use the requested format. In other words:

if the name of your file is "x" and the function is named "f1" you would type it like so (including the "import" line, which is important!)

import x x.f1()

or, maybe you need the function to be inside a loop that's in another file? That would look somewhat like this:

import x While True: x.f1()

hope this helps!
Smudge Apr 5 @ 2:18am 
@dBlueFalcon i had the same issue as @Bita and all i needed to do was put "Movement.Movement()" instead of "Movement()". Thanks!
owenz Apr 5 @ 9:23am 
Originally posted by dBlueFalcon:
it is working for me when I use the requested format. In other words:

...

import x While True: x.f1()

hope this helps!

Originally posted by Smudge:
@dBlueFalcon i had the same issue as @Bita and all i needed to do was put "Movement.Movement()" instead of "Movement()". Thanks!

Yup, that is how it works.

In standard python you would do

from package import function function()

And double checking what is in the game you can do this as well.

Hell, this was even added

from package import function if __name__ == "__main__": function()

Which basically means that if it is not the main program then it will not run this part.

So you can effectively build a lib and the test code for it inside now.

An example would be as follows
sub_program_one.py
def init(param_1=False, param_2=False): if param_1: print("Param 1 was True") if param_2: print("Param 1 was True") def testing(param_1): if param_1: print("Testing suite is printing to debug") print("Tests have started") if __name__ == "__main__": testing()

Main.py
def do_the_thing(): import sub_program_one sub_program_one.init() do_the_thing()

Also, as a very important note wild card importing is a thing just be very careful

Example!
overwrite.py
def fun_1(): print("HAHA, I hacked your function!")

main.py
from overwrite import * # Wildcard imports will mess with name spacing def fun_1(): print("Functions are fun!") if __name__ == "__main__": fun_1()

Guess what happens in the above code!
< >
Showing 1-3 of 3 comments
Per page: 1530 50