Mr H. 402 Posted November 21, 2018 Hi! simple question : is there a way to return an object's init code (set in the editor in its init field, or later with createVehicle) in the form of a string? Share this post Link to post Share on other sites
Harzach 2518 Posted November 21, 2018 I can't believe there would not be, but I also can't find anything. What are you trying to do? Share this post Link to post Share on other sites
Mr H. 402 Posted November 21, 2018 I've made a script that grabs objects and stores their position relative to an object, I'd like to spawn compositions with it and also if needed store what was in the object's init field to re execute the code on the newly created object duplicate. Share this post Link to post Share on other sites
pierremgi 4907 Posted November 21, 2018 There is no getter/setter for objects' init field code. Don't forget the vehicle init is just another code you run when player starts the game. So, you can "read" it as you do with init.sqf (but the init field is unscheduled). The only link with the object (referring to this init field) is the special variable THIS . So, you can script what you want somewhere else with a named object. You can use handle script also. Now, for respawn, or saving position, or whatever reasons like you want to do, one solution is to setVariable on this object: This setVariable ["objectData", [getpos this, getDir this]]; You can even run what you need referring to set/getVariable. Example: this (or object name) setVariable ["MGIcustomCode", ' 0 = [] spawn {waitUntil {!isNull player}; hint ("hello "+ (name player))} ' ]; call compile (this getVariable "mgiCustomcode"); // run as standard init field Later, you can re-run the code, referring to the object, (or the old vehicle, or the killed unit... depending on EHs or module exressions) [] execVM (yourObject getVariable "mgiCustomCode") 1 Share this post Link to post Share on other sites
Mr H. 402 Posted November 22, 2018 Thank you for your answer but that won't work for what I'm trying to do, the goal being to develop a simple composition grabber/ spawner. The idea was that I would for instance create a nice composition with animated characters, the animation would be coded in the characters' init field, this would mean that when I grab a composition I'd also grab whatever code they have and reexecute it when I spawn the composition, for any given composition, quickly and without reassigning scripts. (Which is what I'm doing so far and is rather tedious). Share this post Link to post Share on other sites
Grumpy Old Man 3549 Posted November 22, 2018 1 hour ago, Mr H. said: Thank you for your answer but that won't work for what I'm trying to do, the goal being to develop a simple composition grabber/ spawner. The idea was that I would for instance create a nice composition with animated characters, the animation would be coded in the characters' init field, this would mean that when I grab a composition I'd also grab whatever code they have and reexecute it when I spawn the composition, for any given composition, quickly and without reassigning scripts. (Which is what I'm doing so far and is rather tedious). Don't see why this wouldn't work. You set a variable in the objects init field, just modify the grabber function to also read the variable and store it in the array generated by the grabber, then use it when spawning the composition. Cheers Share this post Link to post Share on other sites
Dedmen 2721 Posted November 22, 2018 If you also give the object a name. You can #include the mission.sqm in the description.ext, then manually parse it till you find the object's name and from there on find the corresponding text for the init script. 1 Share this post Link to post Share on other sites
Mr H. 402 Posted November 22, 2018 4 hours ago, Grumpy Old Man said: Don't see why this wouldn't work. You set a variable in the objects init field, just modify the grabber function to also read the variable and store it in the array generated by the grabber, then use it when spawning the composition. Cheers That's exactly what I'm doing right now, but I'd like it to be automated ^^ 3 hours ago, Dedmen said: If you also give the object a name. You can #include the mission.sqm in the description.ext, then manually parse it till you find the object's name and from there on find the corresponding text for the init script. Thanks I tried looking in the mission sqm, but failed , didn't know I could #include it, with your solution It might just work! Share this post Link to post Share on other sites
pierremgi 4907 Posted November 22, 2018 Just grabbed something which could help, if I understand. You could make some layer in Eden with the objects you want, then: https://community.bistudio.com/wiki/getMissionLayerEntities 1 Share this post Link to post Share on other sites