. . . Posted June 16, 2017 Share Posted June 16, 2017 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 ! Link to comment Share on other sites More sharing options...
Electroely Posted June 16, 2017 Share Posted June 16, 2017 I'm not all that good at modding, but maybe try using inst.isSane = inst.components.sanity:IsSane() inst.isInsane = not inst.components.sanity:IsSane() and then using inst.isSane or inst.isInsane to check? Link to comment Share on other sites More sharing options...
. . . Posted June 16, 2017 Author Share Posted June 16, 2017 Same crash, but thanks for your help man ! Link to comment Share on other sites More sharing options...
Electroely Posted June 16, 2017 Share Posted June 16, 2017 Just now, SuperDavid said: Same crash, but thanks for your help man ! Are you sure the 2 lines I provided are inside the postinit? I tried it myself and it seems to work (although it doesn't update itself automatically) Link to comment Share on other sites More sharing options...
. . . Posted June 16, 2017 Author Share Posted June 16, 2017 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 More sharing options...
Electroely Posted June 16, 2017 Share Posted June 16, 2017 (edited) 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 June 16, 2017 by Electroely Link to comment Share on other sites More sharing options...
. . . Posted June 16, 2017 Author Share Posted June 16, 2017 (edited) 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 ! And I really thought it'd work for sure, hahaha ! Though, thanks for all your help man ! Edited June 16, 2017 by SuperDavid Link to comment Share on other sites More sharing options...
JohnWatson Posted June 16, 2017 Share Posted June 16, 2017 inst.isSane = inst.components.sanity.IsSane inst.isInsane = function() return not inst.components.sanity:IsSane() end Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now