Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Test Subject
Original Poster
#1 Old 24th Sep 2016 at 5:08 PM
Default Calling Remote Function in sim_info module. Syntax error?
OK, I have a bit of a Python programming question here, but seeing how everything I am doing is Sims 4/Python 3.3 based, I'll ask here. The fix is likely something I am overlooking or just a syntax error, but I already spent enough time on this to justify asking. I am far from well versed in python, and only have basic working knowledge of both Python and the inner workings of The Sims 4.

I want to call multiple functions nested inside the sim_info module that have no return value and whose only arguments are "(self)". I want to call them from within an injected script that is injected over a function in the objects.components.state module (among others). The idea is to simply run these sim update functions (lets call them functionname()) in sim_info when certain triggers are met within another module. Here are a few of the methods I have tried:

Importing the sim_info module and calling the remote function directly:
Code:
import sims.sim_info
@injector.inject_to ...
def ...
stock EA code...
functionname()
stock EA code...

-Error: "Global name 'functionname()' is not defined."

Importing the SimInfo Class directly and calling the remote function directly:
Code:
from sims.sim_info import SimInfo
@injector.inject_to ...
def ...
stock EA code...
functionname()
stock EA code...

-Error: "Global name 'SimInfo' is not defined."

Importing the function I am trying to use directly and calling the remote function directly:
Code:
from sims.sim_info import functionname()
@injector.inject_to ...
def ...
stock EA code...
functionname()
stock EA code...

-Error: "Import error: functionname() cannot be found."

Importing the sim_info module and calling the remote function fully addressed:
Code:
import sims.sim_info
@injector.inject_to ...
def ...
stock EA code...
sims.sim_info.functionname()
stock EA code...

-Error: "Global name 'module' is not defined."

I have tried a few other permutations as well, to no avail. I've also tried importing the module within the injected function with no changes. The injection works as expected with no code alterations, so everything is OK there, I am just stuck on adding a single line to execute ANY remote function in another module.

It is odd as I studied how EA/Maxis themselves call remote functions in all of their simulation modules and it seems to be as simple as importing the module globally and then the rest of the classes/functions in that module should have access to a lookup on the functions in the imported module. Maybe injecting over the function somehow messes with this. Sorta stumped why this is not working.

I would appreciate any help or even code snippets from injection mods you have created that feature such a (simple) reference.

Thank you.
Advertisement
Test Subject
Original Poster
#2 Old 25th Sep 2016 at 2:58 AM
I looked for cases where EA had imported anything like sim_info into a module and found plenty of hits on sim_info_type. I followed their import and function call procedure only to get a new error:

Importing the sim_info module and calling the remote function:

Code:
from sims import sim_info
@injector.inject_to ...
def ...
stock EA code...
sim_info.functionname()
stock EA code...


-Error: AttributeError: 'module' object has no attribute 'functionname()'

What I gather from this error is that the import of sim_info failed and the no function called functionname() was found. There must be something different I have to do from what EA/Maxis does to get this to work with the injector.

Like I said before, any examples of a working import of sim_info would be greatly appreciated. I am digging through a few other mods that use scripthoge's injector script right now to see if I can find some useful bits.

Thank you.
One horse disagreer of the Apocalypse
#3 Old 25th Sep 2016 at 8:18 AM
There seem to be very few people who are really managing to get to grips with the python side of modding these days. You could have a wait...

"You can do refraction by raymarching through the depth buffer" (c. Reddeyfish 2017)
Back to top