Help with your scripting

main.lua or equivalent

main.lua or equivalent

Postby epsilonion » 10 Jul 2015, 22:53

Hi guys, I have been looking at one of my old projects that i did when I used to use l**dw**ks and was wondering.....

In the above software there is a main lua file that your main script goes in and as a result you only have to write the main menu/pause menu etc once and it calls each level/scene from there.

Is there a similar way to do that or do I have to write the menus etc etc into each and every scene?

I am a little confused on this point.
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby Shando » 11 Jul 2015, 01:04

Hey buddy,

AFAIK there is no main.lua file, though I could be wrong ;)

I would actually create a separate Menu Scene, and call that when you need it by swapping Scenes (you can always use Global Variables, or an XML/JSON/Text file to recreate any variables that you need to retain - hopefully inbuilt XML/JSON support will be coming soon).

So, you would call your Scenes something like this:

Menu -> Scene1 -> Menu -> Scene2 -> Menu etc.

HTH

Shando

PS: There are also the prebuilt Game State options (GameStart, GamePause, GameOver, GameWin, plus 10 User States) which are detailed in the Scripting Docs - http://www.chi-ad.com/Skyline/API/Lua/html/class_basic___events.html. So, you could use these and have different Menus depending on which State is currently selected?
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: main.lua or equivalent

Postby epsilonion » 11 Jul 2015, 03:10

I have never used states before, I take it I would have to recreate them in each scene.

It confuses the hell out of me tbh..

for instance in each scene when calling the mainmenu state it would load the main menu scene, upon exiting the scene making the call you would then save a file with all the data you require such as player stats, position, scene name (for reloading maybe) etc etc..

Maybe do the same for a ingame pause menu....
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby Shando » 11 Jul 2015, 03:23

Unfortunately, I haven't got time right now to write up a tutorial, but take a look at the resources below and they should help you:

This one is specifically related to Game Programming and seems to be relatively easy to understand (it relates to JavaScript, but don't get put off by that as the principles are the same):

http://codeincomplete.com/posts/2013/12/10/javascript_game_foundations_state_management/

This one is a bit more in-depth and specifically relates to combat design in games:

http://www.adriansotelo.com/Blog/Combat%20Design%20101/Part1/Combatpt1.html

Hope these help??

If not, post back and I'll see if I can put together a quick tutorial on how they work in Skyline.

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: main.lua or equivalent

Postby epsilonion » 11 Jul 2015, 11:24

aahhh, its quite streight forward really.

so for a simple menu > play > menu > quit would I have to copy that into every scene? and use global variables to pass the required info across?

I thought it would have been easier to write it into one file.
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby SolarPortal » 11 Jul 2015, 14:51

For a starting screen with new game, continue, load, quit, options etc.... i tend to make this in its own scene. Then when a button is clicked like new, continue or load; load into another scene.

When you are running in the level though, you cant always load back into the main menu scene to change a setting or save, load a game. This would be more like a pause screen which offers you to save, load, quit to main menu, quit to desktop.

For this i would also use the state system and change the state to the paused state when the p key is pressed and stop all gameplay and load the menu gui. Considering that a pause or main game menu is simply a cheap GUI, it isn't too much work.

Use the scene script per scene to setup the game level menus etc.. easier for copying and pasting or simply save a template scene off and place into the template directory for it too show up on the start screen window, or load from the "File Menu > New from template" and there is also the option of adding all the code into an external script and load everything for the menu at the top of the scene script by including the menu file. Use sky.include("myfile.lua");
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: main.lua or equivalent

Postby epsilonion » 21 Jul 2015, 19:44

OK I am having issues again..
I create a script and save it, everything is fine here until I try to save the script again after making edits and adding more script now when saved it looks like it has saved the script in the script editor until I load another scene then load that one back up again and I find the script was not saved at all.

Another issue I am having is that I have 2 scenes.
1 Main Menu and 1 scene I am creating as a pause menu/game template scene.

The both work independently but when the game scene is loaded from the main menu it gives me the following error, bothe the main menu and pause menu rml files are located in the same workspace for now.

ERROR: Couldn't load file ../../projects/Game/Game.xSkyProjSettings/GUI/Mainmenu/pausemenu.rml
LUA ERROR: loadUI Failed. Did you specify the correct filename or/and workspace folder?


But when loading the scenes indipendantly without using the main menu they bothe work without an issue.
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby SolarPortal » 21 Jul 2015, 19:47

can you send me the files as that error message looks really wrong. It could be a code error in the engine.
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: main.lua or equivalent

Postby epsilonion » 21 Jul 2015, 23:55

Will take a while I am on Mobile.. :D

It seems to be when trying to switch a to a different workspace on the GUI you can load one but it will not load another one.

the error persists after you try to load one scene file (menu) and load another scene file that contains a menu when in this case I load the main menu that has the workspace mainmenu and click on start game the level 1 scene loads but when I press the P key is when the error starts to show then no menu can be loaded only the one from the main menu.

I can load the level 1 scene file and play it in the player and it works but switching from the pause menu to the main menu causes the same error but this time the level 1 menu is the only one that can be loaded. (level 1 menu has the workspace of Pausemenu)

Even when creating a new scene and new menu it can not be loaded and the error persists, the only way to reset it so there is no error is to exit out of skyline and restart.
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby epsilonion » 22 Jul 2015, 00:10

OK heres the project directory;

Included scenes are:
MainMenu -- This is the main menu
Level 1 -- This is a template scene that will be used for all levels.

They can be run independent of each other but when you load one from the other or visa versa only the menu that was loaded first can be used.

MainMenu uses Mainmenu\ workspace
Level 1 uses PauseMenu\ Workspace

Once you get the error and it refuses to load the later menu it can only be run by using the player (game pad icon on the editor) and takes a reset of the editor to get to run them both independently again.

Well thats as far as I have gotten at the moment...

I have banged my head on the well for hours on this one... :)
Attachments
Game.zip
Menu
(4.4 MiB) Downloaded 442 times
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby SolarPortal » 22 Jul 2015, 10:31

looking into this now :)

Edit: I believe these errors are appearing because you are building a project game. We haven't tested projects in some time so it will be good to fix this.
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: main.lua or equivalent

Postby SolarPortal » 22 Jul 2015, 13:09

Fixed: There was an error in code. What happened was when loading the second scene the Filepath structure got messedup. This is due to the fact that we have never loaded between scenes in a project and needed to reference path stuff. Only in the asset library have we done this.

It will now work on the next update :) Thanks again for finding this.
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: main.lua or equivalent

Postby epsilonion » 22 Jul 2015, 15:16

No problems will keep working on the menu system..
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby epsilonion » 22 Jul 2015, 22:12

I decided to wait till the next update is out for loading menus in other scenes and went on with adding more to the main menu.

I copied and pasted the main menu .RML file into the same directory/workspace, renaming it to Newgamescreen and changed the button event function to newgameuiButtonEvent and I get the same errors as I did before about unable to load the new RML file.

I can load the new rml file up but when the issue started again it can not find the file again, I did not open as a project so the paths are getting messed up again and effects saveing.

I found that reloading the scene file fixed it for some reason..

just thought you should know.

Code: Select all
obj    = 0;
winMain = 0;
winNewgame = 0;
function onInit(objID)
   sky.lprint("LUA: GUI Scripts active!");
   obj    = objID;
   gui.workSpace("Mainmenu/");
   winMain = gui.load("PD_StartScreen.rml",0,0);
   -- winoptions = gui.load("options.rml",0,0);
   winNewgame = gui.load("Newgamescreen.rml",0,0);
   gui.hide(winNewgame,winNewgame);                --hide the newgame screen
   --gui.show(winMain,winMain);                   -- used this to try to get the main menu working again.
end

-- The main menu buttons call this function
function UIButtonEvent(btn)
   if(btn=="1")then gui.hide(winMain,winMain);   gui.show(winNewgame,winNewgame); end   --sky.loadScene("Level 1"); end
   --if(btn=="2")then sky.loadScene("Options"); end
   if(btn=="3")then sky.exitGame();  end
end

-- The Start new game menu buttons call this function
function newgameuiButtonEvent(newbtn)
   --if(newbtn=="1")then sky.loadScene("Options"); end
   --if(newbtn=="2")then sky.loadScene("fpsTutorial"); end
   --if(newbtn=="3")then sky.loadScene("Options"); end
   if(newbtn=="4")then gui.hide(winNewgame,winNewgame);   gui.show(winMain,winMain); end
   
end
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: main.lua or equivalent

Postby SolarPortal » 23 Jul 2015, 10:42

hopefully that wont be a problem on the new version ;)
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


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 6 guests

cron