Help with your scripting

start using scripts

start using scripts

Postby cassius_b » 28 Mar 2016, 11:37

Hi
I am new to this engine.I have taken a look at scripting and I don't think learning lua will be a problem but how to start IS the problem.
Lets say I want a simple box object to rotate when the player gets near it, do I attach a script to the box somehow or what.
I could use a simple example on this.
Its not syntax I am concerned with, its how to get INTO scripting from the editor I need.
cassius_b
Skyline Ensen
 
Posts: 154
Joined: 21 Mar 2016, 13:45
Skill: 3D Modeller
Skill: Programmer

Re: start using scripts

Postby SolarPortal » 28 Mar 2016, 12:10

Hi cassius_b,

You can get started with scripting in several different ways:
- Micro Scripts: These are applied to the entity in the scene which may contain a model, light or camera. They bring in the id of the object they are attached to and are the general way of working. Micro scripts cannot be shared across entities unless you copy / paste the code or use the asset manager to drop a .lua file on and convert to microscript. There is no file with the script as microscripts are saved with the scene and will be the most common script type you use alongside the scene script.

- External Scripts: These are similar to microscripts but all the code in stored in a .lua file and must be added to the resources in order to work. These are great for sharing scripts across many entities that do the same thing. Combined with the Dynamic Properties, you can use 1 script across many entities but change the properties on each entity through the Dynamic Properties Panel and using the Custom property setups.

- Scene Script: This is quite self explanatory. It is a script that is first to run in every scene and there is only ever one of them. This can be accessed by right clicking in the scene and bringing up the context menu. Choose "Lua - Scene Script" at the top of the menu. Use this script to control menus and level loading, but it is also possible to do what you want with it.
Note: The scene script does not contain an ID like the other entities since it is not attached to anything in the scene; its actual id is -9.

Applying a Microscript:
First select the entity you wish to apply the script to and then apply/edit a Microscript by either:
- Right clicking in the scene and bring up the context menu, click on the "Lua - Add Microscript" button.
- Or attach the microscript action using the action editor which can also be found on the right click.
- Edit the script from the right click context menu "Lua - [Edit] Micro Script" or from the entities property panel where you will find the microscript action attached to the entity.

Applying an External Script:
First select the entity you wish to apply the script to and then apply/edit a External Script by:
- Right Cliking in the scene and open the menu "Lua - Add External Script", then choose whether you want to create a new script or open an existing one.
- Since the External Script is not an action, you have to remove the script from that sub menu also.

Note: Selecting the entity and dragging a lua file from the asset manager onto the entity will apply the script either as a microscript or external script of your choice.

I hope this helps you :)

Check out Tatties Video Tutorial: Lua Editing on the second to last row in the middle of this list of videos to see the menu being used to apply the scripts:
http://www.forum.aurasoft-skyline.co.uk/viewtopic.php?f=46&t=1107
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: start using scripts

Postby cassius_b » 28 Mar 2016, 12:41

THanks for the answer I think I will be ok now.I know several coding languages including c++ pascal etc.Now for lua scripting ,
cassius_b
Skyline Ensen
 
Posts: 154
Joined: 21 Mar 2016, 13:45
Skill: 3D Modeller
Skill: Programmer

Re: start using scripts

Postby SolarPortal » 28 Mar 2016, 13:05

great, we are here if you need more help :D
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: start using scripts

Postby planetX » 12 Dec 2016, 17:36

Hi, sorry for resurrecting an old post, but I didn't wanted to create a new one just to talk about the same thing.

Let's say I want the Scene Script being external, or having more than one Scene Scripts... is that possible?

I was thinking on adding a cube mesh, make it invisible, and link an External Script to it in order to use it as a Scene Script, where I can manage a bunch of entities, but not being directly linked to any of them. Repeat that process for every External Script I want... Is that ok?

I also was wondering if it's possible to import/include some External Scripts into the Scene Script... that would be great.

To be honest, I don't like the concept of using Microscripts because there is a moment, when the level gets complicated, that I think is gonna be a PITA to check and debug every piece of code if they are flying around inside every object. There's also a risk of losing the code if I delete the object. So I'd like to have all the logic grouped somehow.

Or maybe this idea is stupid... how do you guys manage that?

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Contributor
Skyline Contributor
 
Posts: 210
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: start using scripts

Postby StarFire » 12 Dec 2016, 19:28

Skyline has many ways in which it can be used to achieve the same goal and your ideas are very suited to Skylines workflow. :D

So to recap:

Scene scripts can only be internal - The intention was for a basic scene setup such as ui and global vars, but small games could also use this as a main game script.

Using an empty node or model with invisible material for an external scene script and not using the object in any way other than to add the external script to the entity list.This is a great way to manage a larger project.
object 1 named scene_ui with external ui.lua script.
object 2 named scene_game with external game.lua script.
object 2 named scene_gameOver with external gameOver.lua script etc etc

NOTE: We have plans to add an extra panel in the script editor showing a clickable list of all scripts in the scene, either includes, external or micro scripts.

To include a *.lua file to any script you can call sky.include("myScript.lua");

Hope this helps. :D
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: start using scripts

Postby SolarPortal » 12 Dec 2016, 19:41

The only thing to be aware of with using entities as scene scripts is the order in which they are called.

Most of the time you want a scene script to run before most entities, if they are an entity, then they will update in the order of their ids which may lead to incorrect results if you are dependant on one thing happening before the others, so bear that in mind. You could always adjust the scene file manually in XML to put these entities at the top so they are loaded in first, just backup first :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: start using scripts

Postby planetX » 12 Dec 2016, 19:49

I like very much the idea of importing all the external scripts into the main scene script, so I don't have to mess with entity IDs, init orders and stuff like that (still very new in lua)... what do you think? Any drawback?

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Contributor
Skyline Contributor
 
Posts: 210
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: start using scripts

Postby SolarPortal » 12 Dec 2016, 20:01

The files will be included immediately on script creation after pressing the play the game button and them being included into the scene script which is the first to be created in the chain. So there shouldn't be any drawbacks.

In fact, in c++ we automatically make it include the 2 .lua files found in the Data/Scripts folder. 1 for the options screen for players and a quick utility function addition to improve scripting in scene scripts.

It should work fine :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: start using scripts

Postby planetX » 12 Dec 2016, 20:06

Awesome... thanks to both for quick reply and excellent explanation. ;)

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Contributor
Skyline Contributor
 
Posts: 210
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: start using scripts

Postby StarFire » 16 Dec 2016, 22:21

Your very welcome :D
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 7 guests

cron