Help with your scripting

loading objects by code

loading objects by code

Postby cassius_b » 07 Nov 2018, 23:18

I should have asked this one a long time ago but here goes. Can we load and place characters entirely by code in Skyline?
cassius_b
Skyline Ensen
 
Posts: 101
Joined: 21 Mar 2016, 13:45
Skill: 3D Modeller
Skill: Programmer

Re: loading objects by code

Postby epsilonion » 08 Nov 2018, 09:24

Yes using the API https://api.aurasoft-skyline.co.uk/annotated.html you can even preload presets etc.

the way I personally would go about this is.

  1. Import your model and assign animations etc.
  2. Add a controller by script or via the actions editor (I think the Dynamic controller is the best (my personal option) https://api.aurasoft-skyline.co.uk/classcontroller.html).
  3. Save the char with controller etc as a preset (for this example I used player1 as the filename).
Now you are ready to bring it into the scene via script.
Code: Select all
SpawnID = entity.spawnPreset ("player1",posx,posy,-100,1,1,1);


Now set the Tag of the player brought into the scene so you can reference it via a known tag in other scripts etc.
Code: Select all
entity.setTag(SpawnID,"Player");



You can also Preload mesh and presets so they do not pop in etc

You can use the resource.preparePreset("preset to load in") command

one of the uses for this could be via scene script.

Code: Select all
obj = 0;
function onInit(objID)
    obj = objID;
    resource.preparePreset("Player1");
end


A bit extra

Does entity already exist?
You could also run a check to see if the preset brought in exists in scene already before spawning the player etc in using the following command(s).

In the init section of the script that brings in the player preset,this will make the preset initially spawn and is good practice to declare the variable even though you do not have to in LUA.

Code: Select all
SpawnID = 0;


Check and spawn preset.
Code: Select all
if( entity.exist(SpawnID) == 0 ) then
   SpawnID = entity.spawnPreset ("player1",posx,posy,-100,1,1,1);
   entity.setTag(SpawnID,"Player");
end


OR

Code: Select all
if( entity.exist(entity.getIDFromTag("Player");) == 0 ) then
   SpawnID = entity.spawnPreset ("player1",posx,posy,-100,1,1,1);
   entity.setTag(SpawnID,"Player");
end


Hope this helps.. :D
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 807
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: loading objects by code

Postby cassius_b » 08 Nov 2018, 21:11

Thanks a lot, you have given me lots to work on.
cassius_b
Skyline Ensen
 
Posts: 101
Joined: 21 Mar 2016, 13:45
Skill: 3D Modeller
Skill: Programmer

Re: loading objects by code

Postby epsilonion » 09 Nov 2018, 13:17

No problem any time.. :D
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 807
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 1 guest