Re: Some Plugins

Ok, I'll look into making MExtensions later. Shouldn't be a problem at all.

Right, I've tried to make things simple for this, but it's ended up being a bit weird. My build scripts all expect a folder layout similar to the binary distribution, which unfortunately isn't how scons builds maratis. My setup is as follows (on OSX right now, but the principle's the same)

Harpy:dev pgeyer$ cat ~/.profile 
# other stuff...
#set up Maratis
export MSDKDIR=${HOME}/dev/Maratis-dev/
Harpy:dev pgeyer$ ll ~/dev/Maratis-dev/
total 8
lrwxr-xr-x  1 pgeyer  staff   68  6 Jun 08:14 Bin -> /Users/pgeyer/dev/maratis/trunk/dev/prod/darwin/release/Maratis/Bin/
drwxr-xr-x  4 pgeyer  staff  136  7 Jul 17:27 Plugins
drwxr-xr-x  4 pgeyer  staff  136  6 Jun 08:16 SDK
Harpy:dev pgeyer$ ll ~/dev/Maratis-dev/SDK/*
/Users/pgeyer/dev/Maratis-dev/SDK/MCore:
total 16
lrwxr-xr-x  1 pgeyer  staff  56  6 Jun 08:16 Includes -> /Users/pgeyer/dev/maratis/trunk/dev/MSDK/MCore/Includes/
lrwxr-xr-x  1 pgeyer  staff  61  6 Jun 08:17 Libs -> /Users/pgeyer/dev/maratis/trunk/dev/prod/darwin/release/MSDK/

/Users/pgeyer/dev/Maratis-dev/SDK/MEngine:
total 16
lrwxr-xr-x  1 pgeyer  staff  58  6 Jun 08:15 Includes -> /Users/pgeyer/dev/maratis/trunk/dev/MSDK/MEngine/Includes/
lrwxr-xr-x  1 pgeyer  staff  61  6 Jun 08:17 Libs -> /Users/pgeyer/dev/maratis/trunk/dev/prod/darwin/release/MSDK/
Harpy:dev pgeyer$ ll ~/dev/Maratis-dev/Plugins/*
/Users/pgeyer/dev/Maratis-dev/Plugins/Includes:
total 40
lrwxr-xr-x  1 pgeyer  staff  49 23 Jul 11:09 MEmbedFile.h -> /Users/pgeyer/dev/MEmbedFile/include/MEmbedFile.h
lrwxr-xr-x  1 pgeyer  staff  49  7 Jul 17:26 MEventListener.h -> /Users/pgeyer/dev/MEvent/include/MEventListener.h
lrwxr-xr-x  1 pgeyer  staff  45  7 Jul 17:26 MGameEvent.h -> /Users/pgeyer/dev/MEvent/include/MGameEvent.h
lrwxr-xr-x  1 pgeyer  staff  47  7 Jul 17:26 MSaveFile.h -> /Users/pgeyer/dev/MSaveFile/include/MSaveFile.h
lrwxr-xr-x  1 pgeyer  staff  49  7 Jul 17:27 MScriptExt.h -> /Users/pgeyer/dev/MScriptExt/include/MScriptExt.h

/Users/pgeyer/dev/Maratis-dev/Plugins/Libs:
total 80
lrwxr-xr-x  1 pgeyer  staff  49 23 Jul 11:10 MEmbedFile.dylib -> /Users/pgeyer/dev/MEmbedFile/bin/MEmbedFile.dylib
lrwxr-xr-x  1 pgeyer  staff  41  7 Jul 17:27 MEvent.dylib -> /Users/pgeyer/dev/MEvent/bin/MEvent.dylib
lrwxr-xr-x  1 pgeyer  staff  47  7 Jul 17:28 MSaveFile.dylib -> /Users/pgeyer/dev/MSaveFile/bin/MSaveFile.dylib
lrwxr-xr-x  1 pgeyer  staff  49  7 Jul 17:29 MScriptExt.dylib -> /Users/pgeyer/dev/MScriptExt/bin/MScriptExt.dylib
lrwxr-xr-x  1 pgeyer  staff  69  8 Jul 19:19 MScriptableBehaviour.dylib -> /Users/pgeyer/dev/MScriptableBehaviour/bin/MScriptableBehaviour.dylib
lrwxr-xr-x  1 pgeyer  staff  48 23 Jul 11:10 libMEmbedFile.a -> /Users/pgeyer/dev/MEmbedFile/bin/libMEmbedFile.a
lrwxr-xr-x  1 pgeyer  staff  40  7 Jul 17:27 libMEvent.a -> /Users/pgeyer/dev/MEvent/bin/libMEvent.a
lrwxr-xr-x  1 pgeyer  staff  46  7 Jul 17:28 libMSaveFile.a -> /Users/pgeyer/dev/MSaveFile/bin/libMSaveFile.a
lrwxr-xr-x  1 pgeyer  staff  48  7 Jul 17:28 libMScriptExt.a -> /Users/pgeyer/dev/MScriptExt/bin/libMScriptExt.a
lrwxr-xr-x  1 pgeyer  staff  68  8 Jul 19:19 libMScriptableBehaviour.a -> /Users/pgeyer/dev/MScriptableBehaviour/bin/libMScriptableBehaviour.a

Basically I have my maratis root directory outputting to ~/dev/maratis/trunk/dev/prod/... and then ~/dev/Maratis-dev symlinking to the relevant parts of that. And to allow plugins to use plugins, they're all present within ~/dev/Maratis-dev/Plugins. The only environment variable needed is $MSDKDIR which then points to the current binary distribution root.

Hope that helps.

In other news, I've made a couple of additions to MScriptExt and MScriptableBehaviour.
- MScriptExt - Changed dofile to check a relative path first against the current directory the script is being run in, then against the project root.
- MScriptExt - moved editor script loading into the script rather than being done in C++, which makes it cleaner and less error prone
- MScriptExt - added the following table extensions: table.copy table.compare table.compare_deep table.concat table.contains
- MScriptableBehaviour - fixed getClone bug (wasn't copying the behaviour name across properly)
- MScriptableBehaviour - load behaviour scripts once, and from the plugin script, similar to how the editor scripts are loaded
- MScriptableBehaviour - Used table.copy to copy variables when initialising new behaviours, before if you set a table as a behaviour variable, it was shared between all instances of the behaviour.
- MScriptableBehaviour - added a helper function to get a behaviour assigned to an object ID (ie for a player: local player_bh = player.get(getObject("player")))

Re: Some Plugins

Random question I'm going to cross post on my github mirror thread.

I really think that I would like to host builds of the community branch and plugins so we can get a wider user base who can't/don't want to compile it all themselves. Unfortunately my only dev machine I have available is my macbook right now, as my other boxes are in various stages of dissolution while I rebuild/reformat/repurpose them.

Would there be anyone interested in supporting me with this by helping to create builds? I can provide an FTP account and the hosting, all that would be required would be the occasional building of the plugins and uploading to the FTP. Anything else, such as posting bugs/issues to github and fixing platform specific issues would be nice, but hopefully can be picked up if more people get access to the builds anyway.

Re: Some Plugins

Many thanks for settings, everything compiles perfectly now ! tongue

However, since I've udpdated Maratis fork, MScriptableBehavior doen't work anymore.
I get the following error:
PANIC : unprotected error in call to Lua API (attempt to index a nil value)
Same error when I apply a script and then remove it.

With MScriptExt.so, when I click the pacman (player mode), Maratis crashes after a few seconds. This happens even if this is the only plugin in the project folder.


Nistur wrote:

Would there be anyone interested in supporting me with this by helping to create builds?

Sure, I'd be pleased to contribute in some way. I can provide builds for Linux (Ubuntu).

Re: Some Plugins

com3D wrote:

However, since I've udpdated Maratis fork, MScriptableBehavior doen't work anymore.
I get the following error:
PANIC : unprotected error in call to Lua API (attempt to index a nil value)
Same error when I apply a script and then remove it.

Can you please check that you've definitely updated everything. The issue is currently that MScript{,Ext}::startCallFunction will throw this error if you try to call something like player.update when no player class exists. I _thought_ I fixed when this occurs, but I really need to find how I can do error checking on lua_getglobal and lua_getfield, which are the cause of this.

If it's still occuring, can you let me know which plugins you're using to make sure I've got the same configuration loaded to reproduce it and any scripts you're using that are causing the problem.

com3d wrote:

Sure, I'd be pleased to contribute in some way. I can provide builds for Linux (Ubuntu).

Thanks! I'll PM you details

Re: Some Plugins

I've updated everything today. I'll check more in depth this afternoon.

For now, what I've just found is that I have to put a "/" before "Plugins" in the premake files.
For example in the premake4.lua of MScriptableBehavior :

-- use MGameEvent if it exists
if os.isfile(os.getenv("MSDKDIR") .. "/Plugins/Includes/MGameEvent.h") then ...

instead of

if os.isfile(os.getenv("MSDKDIR") .. "Plugins/Includes/MGameEvent.h") then ...

Don't know if this is a linux particularity...


Is the script that I previously  provided still valid?

Last edited by com3D (2013-07-25 13:58:55)

Re: Some Plugins

post cut off sad

Re: Some Plugins

Ooops, post edited

I've tried with a blank table (just script_name{} in the lua script) and I still have crashes, so script content is not the culprit.

Nistur wrote:

If it's still occuring, can you let me know which plugins you're using to make sure I've got the same configuration loaded to reproduce it and any scripts you're using that are causing the problem.

To simplify, I'm just using MScriptableBehaviour.so (size=306 ko, compiled without the other plugins .h files) put in my project folder, with a blank script as mentioned.

Please note that this issue is related to the update of the Maratis fork.

Last edited by com3D (2013-07-25 14:33:25)

Re: Some Plugins

Right, I realised what this is. It's the error I mentioned before, that it can't find the relevant table 'cause the script isn't loaded. At this stage, MScriptableBehaviour depends on MScriptExt and MEvent because it relies on the MScriptInit event to be fired so it knows when to load the correct scripts.

At some point I'd like to try to make fallback for if you're not using MScript and/or MEvent, but I've got no idea how we can really get around this apart from the pretty hacky solution I had before.

Last edited by Nistur (2013-07-25 17:45:29)

Re: Some Plugins

Does latest MScriptableBehaviour+fork work as expected on your Mac?
If so I'll try to compile for Windows to see if it works.

Last edited by com3D (2013-07-25 18:20:44)

Re: Some Plugins

It does when run alongside MEvent and MScriptExt, if those are missing it crashes as you said. I will try and add a marginally less hacky solution later tonight

Re: Some Plugins

Great, I'll try to build for Windows anyway, in order to be able to provide builds for Windows users soon as everything runs perfectly OK.

Re: Some Plugins

Great, the Windows builds should be more or less the same as the Linux ones (setting environment variables etc) just, you can't symlink the engine nicely (at least... doing so is a little more difficult) so you probably will have to manually create the correct folder structure.

I'm just home now, and have to make food before I can look at any coding, but I'm struggling to think of a nice solution as they all pretty much rely on knowing when the lua state has been cleared to reinitialise things, so I guess I'm going back to the hacky solution of every instance will reload the lua script.

For reference, you can still use the "normal" method (using player { update = function(obj, bh) --[[ ... ]] end, } ) using MScriptExt and MEvent, they will just ensure that the scripts are run at the right time and only once, and allow for the more object oriented approach if you wish to go that route.

Re: Some Plugins

Windows builds status:

~ Fork builds OK with scons. smile

~ I've found a shell program for symlinking, working with any version of Windows, making it as easy as linux big_smile

~ Unfortunately, when trying to compile the plugins, vpaths & _WORKING_DIR can't be assigned/retrieved (nil value error). sad
It seems that these variables have been introduced in version 4.4 (I've downloaded v4.3) so I'll try with latest.


I'm sure nice solution will come to you soon, maybe tomorrow!

Last edited by com3D (2013-07-25 20:54:55)

Re: Some Plugins

Sounds like you're using premake 4.3. It should work with premake 4.4 smile

Re: Some Plugins

After upgrading to v4.4, vs2010 project is generated OK big_smile
However there is a problem with an include : MScriptableBehaviorPublishEventsLua.c not found.

Re: Some Plugins

That's a file generated from MScriptableBehaviorPublishEvents.lua by bin2c.lua when premake is called.
Hrmmm.

Oh! I know why! It's because I implemented os.dir for *nix in the build scripts but I didn't have a working Windows box to write and test it. It just returns an empty list. Great. Sorry about that.

Edit: for now, we could probably just hard code the scripts to be embedded rather than try to list the directory. I'll take a look at it tomorrow

Last edited by Nistur (2013-07-25 21:21:01)

Re: Some Plugins

hi,
how and where to install each of these files?

MScriptableBehaviour
editor   
include   
scripts   
src   
.gitignore   
README.md   
bin2c.lua   
embed.lua   
os.lua   
premake4.lua   
proj-dynamic.lua   
proj-static.lua   

MEvent
include   
src   
.gitignore
premake4.lua   
proj-dynamic.lua   
proj-static.lua

MScriptExt
include   
lua   
scripts   
src   
.gitignore   
bin2c.lua   
embed.lua   
os.lua   
premake4.lua   
proj-dynamic.lua   
proj-static.lua

thanks

Re: Some Plugins

Hi marval. The plugins need to be compiled first. I'm using a build system called premake 4. You can view some basic instructions on how to use it just before the second screenshot in my tutorial. It will then require Visual Studio to build the plugin (assuming you're running Windows).

com3D has offered to provide builds of the plugins so users won't have to go through the above steps (the plugins such as MScriptableBehaviour.dll can just be copied into the project folder) but we have still got a couple of bugs to iron out first.

Re: Some Plugins

thanks Nistur

I am more of an artist than a programmer and although I think it
too complicated I'll take a look at the links

is MScriptableBehavior ( with MEvent and MScriptExt ) the only way to create and access (get/set) "custom" properties/attributes in Maratis lua scripts?

MScriptableBehavior "player" {
    speed = 3,

can I only access and change the speed of a specific enemy in a array?

Re: Some Plugins

If you let us know which OS you're running on, we can try and supply you builds of the community branch of Maratis that you will need, as well as the plugins to test.

Without any plugins, you can assign lua values to objects as follows:

player = {
    obj = getObject("player"),
    speed = 3,
    update = function()
        -- use player.obj and player.speed here
    end
}

function onSceneUpdate()
    player.update()
end

with MScriptableBehaviour alone you can then do something like this:

local player_vals = {}
player = {
    onBegin = function(object, behaviour)
        player_vals[object] = {
            speed = 3,
        }
    end,

    update = function(object, behaviour)
        -- do something with player_vals[object].speed
    end
}

Note: update gets called automatically and you get the object ID passed in onBegin, update and onEnd functions

If you add MScriptExt and MEvent to the project, you can then do this (which is arguably a little nicer)

MScriptableBehaviour "player" = {
    speed = 3,

    update = function(self)
        -- do something with self.speed
    end,
}

Note: if you need the object ID, it's stored in self.__id.object but I'm hoping to remove the need for that soon.

With regards to accessing a specific enemy. It depends on which method of the above you're using, but assuming the latter you can do something like this:

local enemy = getObject("enemy01") -- or some other way to get an object ID
local behavior = player.get(enemy)
local speed = behavior.speed

Hope that all helps in some way smile

Last edited by Nistur (2013-07-27 07:19:35)

Re: Some Plugins

Nistur, is the script that I provided in post #8 still valid according to the mods you've done to MScriptableBehaviour ?
For me syntax is more clear/easy to understand/appealing and it worked fine at that time.

Re: Some Plugins

yes, it will. Until I get time to push to github again, you'll need MScriptExt and MEvent, but it will.

To store any variables you'll need to do something similar to post #9 or the second example above (post #45)

Re: Some Plugins

ok thanks
but for now I prefer to start with the normal method first to understand how the lua script works in maratis
and then I'll try with the plug ins

in this example how to include more players ( instead just one ) and Loop through all of them?

players = {
    objs = more than one player?
    speed = 3,
    update = function()
                   for each player
                              if player speed > 3
                                 player speed = 3

                   
                           
    end
}

Last edited by marval (2013-07-28 02:14:43)

Re: Some Plugins

Try this :

player = {

objs = {getObject("player1"), getObject("player2")}, -- create a table that stores all the players
speed = {-0.4, -2} -- optional : set the speed of each player

}

function onSceneUpdate()

    for i=1, #player.objs do -- #player.objs is the length of the objs table (number of players)
        translate(player.objs[i], {0,player.speed[i],0}, "local") -- example : translate each player at their given speed
        if player.speed[i] > 3 then speed = 3 end
    end

end

NB: update = function() is for Nistur's MScriptableBehavior plugin only.

Last edited by com3D (2013-07-28 07:09:20)

Re: Some Plugins

hi,com3D and  thanks

but the 3 balls only rotates when I turn off the speed property

ball = {
      objs = {getObject("ball1"),getObject("ball2"),getObject("ball3")}
      --speed = {-0.4, -2,3}
}

function onSceneUpdate()
      for j=1, #ball.objs do 
       rotate(ball.objs[j], {0, 0, -1}, 1)
      end
end