Yue Posted August 9, 2018 Share Posted August 9, 2018 How can I access another variable that is in another script? Quote Link to comment Share on other sites More sharing options...
Solution Rick Posted August 9, 2018 Solution Share Posted August 9, 2018 I assume you mean entity scripts (scripts attached to entities). There would be a couple ways to do it. You could link the entity via a script properties. In the script you want to access the other script make a Script variable like say Script.otherEntity = nil --entity. In the properties you'll have a section for this that you can drag and drop another entity in your scene onto. Now you can access it's scripts variables via self.otherEntity.script.theVariableIWant. You could loop over all entities in the world and find the one(s) you want and then access it via entity.script.theVariableIWant. So the idea is once you get a hold of the entity itself it has a .script property which gives you access to it's script variables and functions and there are a couple ways to access an entity from another entity. If you have just a few design time entities #1 works well. If you have a lot or run-time entities then method 2 works well I think. 1 1 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted August 9, 2018 Share Posted August 9, 2018 How do you "loop over all entities in the world'? Talking about an AABB box? 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted August 9, 2018 Share Posted August 9, 2018 Assuming you have the entity the variable is attached to, it's just entity.script.varname. In Turbo, script variables are attached directly to the entity so it's just entity.health, entity.ammo, etc. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted August 9, 2018 Share Posted August 9, 2018 8 minutes ago, havenphillip said: How do you "loop over all entities in the world'? Talking about an AABB box? It's been awhile so I might mess this up, but CurrentWorld().entities I believe would be the list to loop over. Every entity loaded in the current world would be there. Even dynamic ones. It could be expensive so ideally do it on startup. 1 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted August 9, 2018 Author Share Posted August 9, 2018 9 minutes ago, Josh said: Assuming you have the entity the variable is attached to, it's just entity.script.varname. In Turbo, script variables are attached directly to the entity so it's just entity.health, entity.ammo, etc. In Turbo, will it be possible to add multiple scripts to one entity? 1 Quote Link to comment Share on other sites More sharing options...
Rick Posted August 9, 2018 Share Posted August 9, 2018 2 minutes ago, Yue said: In Turbo, will it be possible to add multiple scripts to one entity? I think that would be tough to do given the functions/variables are right on the entity itself. If 2 scripts share names by chance you wouldn't be able to differentiate them. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted August 9, 2018 Share Posted August 9, 2018 2 minutes ago, Yue said: In Turbo, will it be possible to add multiple scripts to one entity? No, that would be bad. With one script, we can just say "entity.health", entity:TakeDamage(5), etc. I want it to get simpler, not more complicated. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 10, 2018 Share Posted August 10, 2018 Just for reference sake: 1 Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 10, 2018 Share Posted August 10, 2018 The methods I have been using are; Importing the second script, Making variables global, and using a pick to get the value. The method varies depending on how you want the code to work. If you want the script to attach to multiple entities but the functions to be per entity I find the best way is using a pick. And if I want to add multiple scripts the best method I have seen is using pivots and making them children of the entity. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.