Scripting API

Re: Scripting API

Postby acme_pjz » 19 Apr 2013, 05:11

Edward_Lii {l Wrote}:And who knows, maybe the onSave and onLoad events can be used for some interesting puzzles? ;)


Not really :D At least it won't work when replaying the level record :lol:

BTW, is it useful to allow each block has its own local variables, just like C++ classes? And is it hard to implement?
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby acme_pjz » 29 Apr 2013, 05:44

Hi everyone,

Recently I created an icon for block with scripts. It's 16x16 icon, but I think it's dull :| Are there anyone wants to make a better icon? :)
Attachments
script-icon.png
script-icon.png (790 Bytes) Viewed 4373 times
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby odamite » 29 Apr 2013, 14:32

Hello acme_pjz,

Here's my take on the icon. I tried to follow the new inky-style. However I think that looks a bit out of place on a block but fine in the popup menu.
scripting.png
scripting.png (675 Bytes) Viewed 4365 times
User avatar
odamite
 
Posts: 166
Joined: 16 Jan 2012, 16:28

Re: Scripting API

Postby acme_pjz » 29 Apr 2013, 14:54

Hi odamite,

Your icon is better than mine :) Don't know if it will better if horizontally flipped because it will looks like "S", which is the first letter of "Scripting" :lol:
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby Edward_Lii » 29 Apr 2013, 14:58

Hello odamite,

odamite {l Wrote}:Here's my take on the icon. I tried to follow the new inky-style. However I think that looks a bit out of place on a block but fine in the popup menu.

The icon looks great. ;)
About it looking out of place on the blocks, I agree, but it's very useful to see which blocks have scripts and which don't.
Maybe we could add a key binding that, once pressed, will show the icon for blocks with scripts. :think:
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Scripting API

Postby acme_pjz » 04 May 2013, 14:15

Edward_Lii {l Wrote}:...
I fully agree, I implemented an enable state for blocks to substitute dynamic addition and removal of objects.
This way blocks can be disabled and re-enabled through scripting making them fully disappear, both visually and collision wise.

I found a minor problem, the moving blocks already have a property named "enabled", so if we want to expose it in scripting API we have to rename it :| maybe "activated"?
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby Edward_Lii » 04 May 2013, 14:36

Hello acme_pjz,

acme_pjz {l Wrote}:I found a minor problem, the moving blocks already have a property named "enabled", so if we want to expose it in scripting API we have to rename it :| maybe "activated"?

I assume you mean rename the new enabled property to activated?
If so, go ahead and change it, the enabled property probably isn't used in any levels yet. ;)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Scripting API

Postby acme_pjz » 04 May 2013, 17:06

Edward_Lii {l Wrote}:I assume you mean rename the new enabled property to activated?
If so, go ahead and change it, the enabled property probably isn't used in any levels yet. ;)


No, I mean the old enabled property of moving blocks :| Change it will only affect UI translation, though. IMHO it's confusing if a block becomes invisible when we "deactivate" it :|
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby Edward_Lii » 04 May 2013, 19:46

Hello acme_pjz,

acme_pjz {l Wrote}:No, I mean the old enabled property of moving blocks :| Change it will only affect UI translation, though. IMHO it's confusing if a block becomes invisible when we "deactivate" it :|

I agree that "enable" is a bit more logical than "activated", but how do you plan on changing it?
Only naming it "(de)activated" and keeping the name in the file "disabled" for backwards compatibility will make the level files look weird:
{l Code}: {l Select All Code}
tile(ConveyorBelt,450,300){
   disabled=0
   enabled=0
   speed=2
}

:|

Maybe we should rename it both in the UI and the levelfile, but remain compatibility with the older name?
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Scripting API

Postby acme_pjz » 05 May 2013, 09:27

Hi,

Edward_Lii {l Wrote}:I agree that "enable" is a bit more logical than "activated", but how do you plan on changing it?
Only naming it "(de)activated" and keeping the name in the file "disabled" for backwards compatibility will make the level files look weird


OK, then change the new "enabled" property to "visible"? :| And a notice to level designer that an invisible block isn't involved in game logic :|

BTW, the new "enabled" property doesn't save to the level file, right? It can be accessed with script only :|
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby Edward_Lii » 05 May 2013, 10:55

Hello acme_pjz,

acme_pjz {l Wrote}:BTW, the new "enabled" property doesn't save to the level file, right? It can be accessed with script only :|

Not yet, I wasn't sure if this was needed.
It makes sense that if it can change during runtime it can be (pre-)set in the level file, just like the fragile state, etc...

Then again, the enabled state doesn't play nice with the leveleditor, the blocks are invisible while editing.
:think:

What if we do as you suggested first, rename the old enabled to activated/deactivated, since it makes sense for moving blocks and conveyor belts to be activated.
We won't read/store the new enabled property in level files, if the levelmaker wants a block to be disable at the start of a level he must script it in an onCreate script.
This solves the problems with editing disabled blocks. :)

The only thing left is the way it's named in the level file. We should still read the disabled setting for backwards compatibility, but maybe we should also start supporting "activated = 1"?

P.S. Sorry for the inconvenience. :p
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Scripting API

Postby acme_pjz » 20 May 2013, 13:26

Hi Edward_Lii,

I have some suggestions. Currently the script code is compiled every time when script is executed. I think it will affect game performance :| I'd like to change the code to compile the script after the level is loaded (in level editor, after test play button clicked). We could also add some get/set function to script APIs to allow script change the event handler at rumtime :) . Is it a good idea?
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby Edward_Lii » 20 May 2013, 14:56

Hello acme_pjz,

acme_pjz {l Wrote}:Currently the script code is compiled every time when script is executed. I think it will affect game performance :| I'd like to change the code to compile the script after the level is loaded (in level editor, after test play button clicked).

I think this is a good idea, not sure if the performance gain is noticeable on the desktop, but it is probably on mobile devices. :)
One thing to keep in mind is that you can't use luaL_loadstring or luaL_dostring since they expect a null terminated string and Lua bytecode can contain null characters.

acme_pjz {l Wrote}:We could also add some get/set function to script APIs to allow script change the event handler at rumtime :) . Is it a good idea?

If it isn't too hard to implementing it, sure. Not sure if it's really needed for most levels.
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Scripting API

Postby acme_pjz » 21 May 2013, 04:04

Unfortunately, I can't find a way to reserve a Lua variable for future use :( , except for some extremely ugly ad-hoc tricks (for example save some temp variables in Lua state)

[EDIT] Ah, I found it, using LUA_REGISTRYINDEX, luaL_ref and luaL_unref :D
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby acme_pjz » 04 Jun 2013, 10:25

Hi Edward_Lii,

Edward_Lii {l Wrote}:Added a game library to the ScriptAPI, it can be used to retrieve time and number of recordings as well as winning the level through scripting.
There is a "level" library already. I think maybe we should merge them? :)
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Scripting API

Postby Edward_Lii » 04 Jun 2013, 11:03

Hello acme_pjz,

acme_pjz {l Wrote}:There is a "level" library already. I think maybe we should merge them? :)

Yeah I think that isn't such a bad idea. :)
For some reason I thought it didn't really fit the level library since the time playing isn't really part of the level, but more the game mechanics.
But then again, it's probably better to keep the library count low and extend existing ones.

I've merged the game and level library in svn rev. 671. ;)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Who is online

Users browsing this forum: No registered users and 1 guest

cron