Jump to content

Kenneth Nyström

  • Content Count

  • Joined

  • Last visited

Posts posted by Kenneth Nyström

  1. I am having trouble saving "prefabs" as "the "Leadwerks" engine" doesnt make a meta file when I save a prefab: and as such when I open the prefabfolder containing a file that does not have a .meta counterfile "the engine" crashes (and messes big time with my Windows) I even had to reinstall Windows a few times because of some corrupted files: and now i cant save prefabs at all.

  2. On 1/12/2019 at 4:56 AM, reepblue said:

    From my understanding, no. You need to call the use the Steamworks API with C++.

    You can always expose these classes yourself if you have the professional version.

    Am I correct in assuming one need add //lua to the following C++ "external dependencies"
    line 88
    class ISteamUserStats

    and make it
    class ISteamUserStats//lua 
    to expose the class

    and to line 90
    add say
       static void SetAchiv1()//lua 
    as activator.

    or do one need do that in like the header files section? 
    or even the source section?
    the code from line 88: isteamuserstats.h

    class ISteamUserStats
        // Ask the server to send down this user's data and achievements for this game
        CALL_BACK( UserStatsReceived_t )
        virtual bool RequestCurrentStats() = 0;

        // Data accessors
        virtual bool GetStat( const char *pchName, int32 *pData ) = 0;
        virtual bool GetStat( const char *pchName, float *pData ) = 0;

        // Set / update data
        virtual bool SetStat( const char *pchName, int32 nData ) = 0;
        virtual bool SetStat( const char *pchName, float fData ) = 0;
        virtual bool UpdateAvgRateStat( const char *pchName, float flCountThisSession, double dSessionLength ) = 0;

        // Achievement flag accessors
        virtual bool GetAchievement( const char *pchName, bool *pbAchieved ) = 0;
        virtual bool SetAchievement( const char *pchName ) = 0;
        virtual bool ClearAchievement( const char *pchName ) = 0;

    I am just confused after having spent 12 hours trying to figure out how to use the
    ToLua++ generator;
    virtual bool SetAchievement( const char *pchName ) = 0;   
    I strongly suspect I need to use the ToLua++ to generate two files of  some code. to be able to use the commands from inside a lua script.
    and with that (luascript) using an


    that the C++ scripts (running in the background (behind the "game window")) can interpret:
    and then run a bit of code;

    class XxxXxxxxx//lua
       static void :ZzzZzzz() 

    That then in its turn uses the preset "external dependencies .h scripts (in this case ISteamUserStats.h that has its ISteamUserStats//lua (exposed))

    allowing the
    SetAchievement("A_TEST_ACHIV") code to be sent to steam...

    and thru that activating the steam achiv
    However I am still missing something...

    (I suspect it has to to with I havent gotten an grasp of what the ToLua++  generatoris supposed to do and work/how to be used)

    Need an pointer on where to look next as my head is spinning hard (again) as I cant see what I am missing atm.
    I even have an suspicion there is an built in steamworks lua to c++ (due to the steam interface reacting to shift + tab from with in the game) that is already working and that I only need to understand how to use the 



  3. Hello; I am trying to figure out how to use the following in a Windows based environment;
    and I think I have gotten down to the code I want activated in/thru the c++
    class MySingleton
       static void SetAchiv1()
            set_steam_achievement ("FINISHED_AREA_1");
    = when I use in Lua the below
    I would (example) activate set_steam_achievement ("FINISHED_AREA_1")
    However I am a bit confused in how to set up the C++ bit as it seems to involve several files.
    However as this is a Linux based discussion im wondering if someone could give me a pointer toward how to find information on 
    making the same (but in Windows) as in the first input above by pracedru


    "I work on Ubuntu 15.04. Here the tolua++ libs are installed with:




    sudo apt-get install libtolua++5.1-dev



    The tolua++ program needs a pck file which shall contain the c++ like seudo code that is translated into lua classes."



  4. Q: Is there a way to call a C++ script from a Lua script? 
    and if that is possible;
    how does one call a Lua script from within a C++ script?
    Any pointers appreciated

    im thinking; if that I can at the end of a level, have LUA script ask for a C++ script that triggers a Steam Achivement and after that either calls the desired in game map or if nedded restart the entire game (this is a viable option for me; but not desirable if avoidable)

  5. On 1/11/2019 at 9:36 AM, AggrorJorn said:

    Please, for future posts, attach your entire script in the question (and in code format). The community wants to help you and the more information you provide, the faster you are going to get a solution. 

    Its the basic "player" script that comes with Leadwerks...so really no need to attach the script...

  6. I have the exact same question....and I get the steam partner thingy part... and that I have to use Microsofts; Visual studio but there is an multitude of versions of M: VS.. which one is the correct? (I think I have figured out how the code must look like)
    But what program to use is the next step?
    and how do I reach the Leadwerks C++ stuff.

    Is it just to start M: VS and find your correct script and type in the code?

    cant find the preexisting scripts I want (re)written with/in C++.. within M: VS.
    (I know this is outside Leadwerks) but does someone know how to find the files?
    I suspect im gonna need Code::Blocks and thru that find the files i want... (am I correct?) No I guess thats for...Linux... hmm

    Ahh wait there is an open folder in M: VS...is that the way?

  7. 5 hours ago, AggrorJorn said:

    Without seeing the actual script you have right now, we can only guess as to why it doesn't work. The script:hurt() function looks a little of. I think you want to use:

    if window:KeyHit(Key.U) then
       self:hurt (100)

    See this tutorial on functions



    Yes that is exactly what I thought it would be, but somehow it doesnt work. (head began spinning after hours of it not working althou it looked like it should be working) will go bk and look at it again now after an nights sleep, but yeah it looks like I originally thought... hmm.
    and I pretty much used the basic "player" template that leadwerks comes with with no major changes. 

  8. Hello: need assistance to figure out a small script (to use within the "basic" player script) to give my own player damage when pressing a certain key: 
    Just using a keyhit (Key.U) to trigger a respawn (within the "player script) ( to have the player be able to get out of situations they are stuck in or have fallen thru the map)
    I thought the below would be enough...but I cant get it to work:
    (my Health amount is 100: and I tried using the script.hurt)
    if window:KeyHit(Key.U) then
    script:hurt (100)
    I also tried using
    self.health = self.health - self.health 
    (in several configs and a bunch of other ways i have forgotten about now after 3 hours of trying to figure this one out.)
    As said I want to be able to press a key to lower my health so I can use/trigger the ingame respawn function if the player either gets stuck or falls thru the map (after that)
    (and damaging my player health logicly should been the easiest way to do it; as that would trigger the respawn function: but nah, it wasnt that easy at all.)



  9. 7 hours ago, aiaf said:

    You should save to disk only what is needed to recreate the state you where in.

    For example say you want to remember player position and the current map:

    { x = 0, y = 0, z = 0, currentmap= "level2" }

    Save this to disk.

    Load function at start of game.Set player position and load the level from the disk data.


    Start small think what is needed to be saved. And do some small tests.


    Ways to save to disk:

    This lib can help by serialize lua tables:



    Other option is to use api provided by leadwerks:



    Another solution is to use sqlite.


    Yeah I am thinking as small as possible; I only really need 
    1: what map was the player on: 
    2: optional------------(the position) (more then enough with just the normal: map-spawn- in-point) 
    3: two table values;  thats cruicial to the "where in the game progress the player is" 
    4: save to disk
    5 load when game starts.

    But I am absolutly CLUELESS where to begin. = I cant get anything to even begin make sense without a starting point where the save scripts is to be put.
    (there are no tutorials to be found)
    I can (in my mind) see how I only need like 5 or 6 lines of code to make this to be solved

    Something like this:

    function Script:SaveData()                      --This is to get the function goin.
        count1 = (count1 + 1)                          --This I hope is to name the save files diffrently each time a save is done

      {currentmap= "self.mapname" }    --This line of code should possibly incl, the two table values of "lets call them "mylevel" & "mybuildlevel"

        local entityTable ={}
        {mylevel= "self.mylevel" mybuildlevel ="self.mybuildlevel" }
        return entityTable

    Let me see if I have gotten the basic idea of what the load script should say:

    function Script:LoadData(data) --This is to have the load scrip going. (Game comes with a first "save" that has the starting values going                                                    --the first time it is started up; before the game saves its own save file for the first time)

                                                  --here I suspect a line of code needs to be put in to identify the latest save; so game knows what file to                                                    --load

    currentmap = ""                     --the saved value above in save file
    mylevel =  ""                          --the saved value above in save file
    mybuildlevel = ""                     --the saved value above in save file



    Any help to move me forward will be very much appreciated.


  10. So I have been putting this step off for some time.
    "the save function."
    I have this basic idea how and where it should be implemented:
    But the Leadwerks "index" for the save function is to say the least lacking regardng the "SaveData" and "LoadData"
    so I am actully stuck in my endevours to proceded with my game´s save/load function.

    Especially the part with how to "save" the map: one is currently on within the game, so when the load funtion is activated.

    the "correct" map is loaded,

    I strongly suspect:

    "SetCurrent" & "GetCurrent" (world) is the way to go.
    but how should it be implimented?

    Having the hardest time to figure out what the save part should look like to include the GetCurrent (world)


    function Script:SaveData()
        count1 = (count1 + 1)
        prefab = self.entity:GetKeyValue("prefab")
        pos = self.entity:GetPosition()
        rot = self.entity:GetRotation()
        world =????????           --is it? self.entity:GetCurrent (world)

        local entityTable ={}
        entityTable.posx = pos.x
        entityTable.posy = pos.y
        entityTable.posz = pos.z
        entityTable.rotx = rot.x
        entityTable.roty = rot.y
        entityTable.rotz = rot.z
        entityTable.prefab = prefab
       --is it also? entityTable.world =world

        return entityTable

    Let me see if I have gotten the basic idea of what the load script should say:

    function Script:LoadData(data)

        r1 = data.rotx
        r2    = data.roty
        r3    = data.rotz
        p1 = data.posx
        p2    = data.posy
        p3    = data.posz
       world = data.mapname     --is this correct?

        self.entity:SetCurrent (world)    
        System:Print('Entity Loaded')

    Any pointers much appreciated as I am getting back into headspinning mode (again) but something tells me I might be getting closer to what I want to achive with my save/load scripts.

  11. On 10/23/2018 at 4:55 AM, Wafflesoft said:

    What I ended up doing with  my game was removing all the code that says what happens if the player dies. Then inserted my own code that says; teleport to respawn location, reset health, reset stamina, reset thirst, reset hunger, empty inventory.

    Using this method the player technically doesn't die but it simulates death. Then all you have to do is for your enemies is add code that makes thier target nil and tells them to search for new target.

    But as for your code the only thing I can suggest is set up a trigger value and then breadcrumb. So for example add something like;

    Script.trigger = 0

    Then in your update world add;

    if self.health <= 0 then

    self.trigger = 1


    if self.health > 0 then

    self.trigger = 0


    if self.trigger == 1 then

    --Add the code here that triggers or references the change map.



    On 10/23/2018 at 4:15 AM, Gonan said:


    This problem occurs when more than one monster is attacking you. Not sure if it was ever fixed.


    Both; Thank you for your inputs. and yeah I thought the same way with working around the problem (acctully a very good thing); taught me alot of useful "stuff" while dealing with the LUA code.

    I really only have one last issue with the coding I will soon dive into:

    Hmm I could just ask you guys (without starting yet one more thread):

    making the code for saving, 
    is there a good place to begin lookin @?
    (didnt find the info in the "index" (could be there; this is just me just getting to that stage of/in the programming)



    29 minutes ago, havenphillip said:

    I think the line


    was causing crash problems. Maybe uncomment that.

    Hmm I tried it -- and several alternatives to SetMass thruout the kill/respawn part of the script.
    still same result in the game crashing.

    Only wierd i can see is that the Output says.

    "process complete"

    Without having reached the loading bit of the ChangeMap script it usully does...


    I perhaps I need find a "never" version of the respawn  bit in the script (using lesson 27 of the LW tutorial) and it has worked great until now when it messes with the changemap script...


    Anyone can point me in a direction for an alternative place/tutorial  for a wiew into a diffrent version of a respawn script?

  13. Gamecrash; due to kill/respawn script changes/removes??? a value that is used within the default "TriggerChangeMap.Lua" script

    My suspiscion atm...have had like 20 other ideas before:what it might be (not working);
    Is that the respawn script is missing something (but My skill isnt yet up to that level yet so i can see what is missing. If that is the case. (yes im suspecting there is missing an "if" statement but not sure) (I have gotten to the point I cant keep track of all my ideas flying around what it might be)
    = time to ask:
    Before dying the game and its Changemap scripts work just fine:
    But after dying once:
    Game just hangs it self when entering the TriggerChangeMap script...

    ::::::::::::::::::::::::::::::::::::::::::Player.Lua "script":::::::::::::::::::::::::::::::::::::::::::::::::

    function Script:Kill()
        self.corpse = Pivot:Create()
        self.alive = false

        local shape = Shape:Load("Models/Characters/Generic/corpse.phy")

        if shape~=nil then shape:Release() end
        if self.weapons[self.currentweaponindex]~=nil then
        local maxomega=5
        local v = self.entity:GetVelocity()
        if v:Length()>1 then

    function Script:Respawn()
        self.alive = true
        self.health = self.maxHealth




    ::::::::::::::::::::::::::default "TriggerChangeMap.Lua" script::::::::::::::::::::::::::::::::::::::::::

    function Script:Start()


    function Script:Collision(entity, position, normal, speed)


    function Script:Enable()--in
        if self.enabled==false then

    function Script:Disable()--in
        if self.enabled then

  14. Question 1:
    How to set a script so if a global value is <= an object "always"  stays hidden.
    (been fiddling around with various alternatives (gettng clearly better as I can debunk to a certian level now)

    Having it difficult to identify what keywords makes an object "remain" toggled hidden or shown if I map/area swap and then later returns to the same (hub) map ...

    I suspect it is done with an global value 

    Deactive = nil


    later/another "trigger script" changes the value when "triggered"
    Deactivate = 1
    In the Object in question (i want to hide/show) and its script
    is where it gets tricky for me.
    How to formulate the script so it turns "hidden" on for the object.

    when  a value is <=  (equal to or bigger).


    there is a few thoughts about the above but I suspect its better i get a push in the right direction then speculate to much at this stage in my learning. (Last day I have made (for me good progress) want to keep that "flow going for just a bit longer
    Thank You for help in advance.

  15. So I am moving along with this video tutorial series  # 25 checkpoint manager  @ around 1143: on YT to get the hang of the basics.

    but I get a  '=' expected near 'function'

    (on the 6th line from end: function Script:GetCheckpointPosition()

    I cant figure out why it isnt working. (pretty sure I have followed the instructions right) triple checked the text...


    Script.defaultCheckpoint = "" --entity "Default checkpoint"
    Script.currentCheckpoint = nil

    function Script:Start()
        if self.defaultCheckpoint == nil then 
        error ("No default checkpoint")

        self.currentCheckpoint = self.defaultCheckpoint


    function Script:GetCheckpointPosition()
        return self.currentCheckpoint:GetPosition(true)

    function Script:GetCheckpointRotation()
        return self.currentCheckpoint:GetRotation(true)


  16. So I have tried and tried and tried; to change an objects mass thru a script.

    I basicly want to have an trigger (activate) "change" a mass in a diffrent object thru two scripts

    I have done and redone this so many times my head is spinning so hard ; I cant figure this out now. 
    (I kid u not spent 20 hours to try solve this on my own)

    trigger script be like: set the "global" value with

    object script

    if getmass=2 then SetMass (5)


  • Create New...