Jump to content

Way to use "local something" in all functions?


Recommended Posts

Hello, I have a question if someone can help that'd be great :)!

So, I was just wondering if there's a way that I can for example use these

local sane = inst.components.sanity:IsSane()
local insane = not inst.components.sanity:IsSane()

everywhere in my code without having to copy paste them in every single function?

Cause copypasting these in like 20 functions really adds up to a lot of local stuff... I tried placing it out of the master_postinit but I got a crash like "inst is not declared" or something, is this possible to do?

Thank you for your times, have a good day/night :D!

Link to comment
Share on other sites

I'm trying to do it outside of the postinit, cause my functions are outside of the postinit.

Wouldn't putting something local inside the postinit only allow to use it inside the postinit & not the functions outside of it?

Link to comment
Share on other sites

15 minutes ago, SuperDavid said:

I'm trying to do it outside of the postinit, cause my functions are outside of the postinit.

Wouldn't putting something local inside the postinit only allow to use it inside the postinit & not the functions outside of it?

but inst.isSane would not be a local variable. Instead, it would be a variable contained inside inst. So it would be different in every entity yet it won't be a local variable (local as in only useable inside the scope it was assigned in).

...That's just how I understand it, anyways.

Edited by Electroely
Link to comment
Share on other sites

Oh, I didn't notice you said to not use local xD.. So, I tried your idea & put-

inst.sane = inst.components.sanity:IsSane() -- Sane
inst.insane = not inst.components.sanity:IsSane() -- Insane

-inside my master_postinit but when I used them inside my local function (which's outside of postinit) to check if (in)sane...I got no response unlike the local inside the function :shock:!

And I really thought it'd work for sure, hahaha :)! Though, thanks for all your help man :D!

Edited by SuperDavid
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...