|Tim Derks (timmiej93)||14.03.2017 19:23|
|For a mod I'm making, I'm adding an i3D file to a placeable by using "Utils.loadSharedI3DFile()". This all works fine. I then get the child at index 0, to get the first object actually inside the i3D file, and I then try to add a trigger to that object (this all is appended to the "finalizePlacement()" method of the placeable).
When this is triggered by placing a new instance of said placeable, this works fine. The trigger gets added, and the trigger callback works. However, when the "finalizePlacement()" method is called upon loading the map (when an instance of the placeable is already placed and saved on the map), the trigger is -not- added, or at least doesn't function properly. Am I doing something wrong here?
I would like to check if adding the trigger actually worked, and show an error for myself if it didn't work. Is this possible?
|Emil Drefers (Unknown)||15.03.2017 07:27|
addTrigger() will propably throw an error if the passed object is not a physical object.
Your approach should work, if you have a look at the
Adding some print() to your code might help debuging.
You could adjust the collision mask of the trigger to able to test it easier (vehicle vs player).
|Tim Derks (timmiej93)||16.03.2017 20:44|
I actually used the greenhouses as an example, since those add a playerTrigger, which I'm trying to add too.
The strange thing is that my code -does- work just fine when I just placed the placeable, or at least placed it in this play session.
It's when I place the placeable, save the game, then quit and load the game, when the triger does -not- work.
I suspect this has something to do with using "Utils.loadSharedI3DFile()" before the game has actually started properly (since the finalizePlacement() functions get called while loading the savegame), but I don't know what to do about it. Do you have any suggestions?
Upon further research, I found a "loadFinished()" callback in the vehicle specification, which might help me. I saw that the "Utils.loadSharedI3DFile()" function is used with many more arguments there, but unfortunately, I haven't got a clue what most of these arguments are. Could you explain?
Utils.loadSharedI3DFile(self.i3dFilename, baseDirectory, true, false, true, self.loadFinished, self, data)
The i3D name and base directory are pretty self explanatory. The 3 following booleans are a mystery to me. The self.loadFinished is the callback function for when the load is complete. I don't know why self is passed here, but I do know that data is an array with some data that the loadFinished() function uses. It'd be great if you could explain the unknown arguments to me.
Eureka! I was using the "Utils.loadSharedI3DFile()" method with these arguments: i3D file name, mod directory, and two booleans. Don't ask me why, I think that's the way I first found the function, so I assumed it's the correct way of using it. Now, with just the i3D filename and mod directory, it seems to be working. I'll be testing this to make sure it really works.
But now I really wonder, what do those boolean values do?
|Emil Drefers (Unknown)||21.03.2017 06:55|
Utils.loadSharedI3DFile(filename, baseDir, callOnCreate, addToPhysics, verbose, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments)
I guess the parameters are self explanatory?
|Tim Derks (timmiej93)||21.03.2017 20:51|
Thanks for explaining, that definitely helps. I do have some questions though:
1. What is 'verbose' supposed to do? I assumed it would print more information to the console/log, but it doesn't seem to change anything?
2. Can 'asyncCallbackArguments' be nil when 'asyncCallbackFunction' and 'asyncCallbackObject' are not nil?
2.1 Does 'asyncCallbackArguments' have to be similar to the 'data' table, as seen in the vehicle specialization (line 105), or can it contain anything?
|Emil Drefers (Unknown)||23.03.2017 07:05|
1) It is more or less only usefull when something goes wrong ;)
2) yap, the arguments can be nil
3) nope, that variable/table can have any structure/information you want
Note: Log in to post. Create a new account here.