Jump to content

Phodex Games

Members
  • Posts

    275
  • Joined

  • Last visited

Posts posted by Phodex Games

  1. 19 hours ago, Rick said:

    Every time you load a new map it should be starting fresh with script variables.

    Hi Rick. Yes this is exactly what I meant. I will do some debugging and researching on this, but could this be a Leadwerks bug maybe? Maybe I made some mistake somewhere we will see...

  2. 8 hours ago, macklebee said:

    Why would the variable get set to nil unless you program it?

    Well maybe I formulated this wrong. I mean variables don't get saved on their own if you change maps. The weird thing is it works the first time, but second time I change the map it doesn't. Even tried diffrent maps. I also tried the Cleanup function & the Detach function to set the variable to nil, but still the problem exists.

  3. Hi,

    I have a general inventory script attached to every object, which should have an inventory. In the script settings of the inventory script I put an "firstSlotOffset" value, to adjust where the inventory starts to render its slots. In code this looks like that:

    Script.firstSlotOffset = Vec2(0, 0) --Vec2 "Slot Offs."

    In the start function I do some calculation:

    self.firstSlotOffset.x = self.firstSlotOffset.x * context:GetWidth()
    self.firstSlotOffset.y = self.firstSlotOffset.y * context:GetHeight()

    The problem is if I load to another map and back to some other map the self.firstSlotOffset value seems corrupted. This happens only after I loaded twice (so changed the map two times). I found that out by printing the self.firstSlotOffset value in the start function. What I mentioned is if you loaded twice the self.firstSlotOffset value is not what is set in the script settings but the result of the above calculation which should not be. If you change a map, all variables should be "nil"-ed shouldn't they? And by the way what do you have to take care on when loading to an new map? Do you need to clean stuff up and if yes which stuff? I guess that could be the problem that I didnt clean up.

     

    P.S.: The error only appears for the player inventory, which is the only entity staying the same on both maps I load to.

  4. Hi, I personally use Dropbox and load the project directly out of the Dropbox folder, so I dont have to copy my files everytime. This works pretty good so far. Just download Dropbox for your Desktop, put your project folder into the local Dropbox folder and in the Leadwerks projectmanager import that project, but I had some issues now and then with overlapping files (luckily Dropbox always keeps both files) and Dropbox sometimes seems to block leadwerks from accessing specific files like maps.

  5. EDIT:

    Just found out that the error was somewhere else ^^. The below code just works fine. Anyway thank you for the help :).

    Hi there,

    I faced some weird behavior, testing and debugging my project. The following shows the structure of my code, it would be very kind of you, if you could tell me if you can find any error, because I dont. Maybe I messed around with global/local/script variables, which I know, often cause such errors.

    Explanation:

    Of course this script makes no sense, but it should only representate the structure, because it would be way to complicated to explain the issue within the actual script. So what is the problem? When I apply the "Main Script" to one entity, everything works fine and I get printed the data. but if I apply the "Main Script" to more than one, for example two, then the problem occurs. In the output I get the "Send my data!"-message, but now comes the weird thing. It prints the data and then, even if the "Test"-function is just called once it prints "Variable data is nil!" twice. And this happens for both entitys. So this is my output with two entities with the "Main Script":

    • Send my data!
    • Test
    • Variable data is nil!
    • Variable data is nil!
    • Send my data!
    • Test
    • Variable data is nil!
    • Variable data is nil!

    Main Script:

    Script.dataToSend = "Test"
    Script.data = nil
    
    import "exampleScript.lua"
    
    function Script:Start()
    	self.myLuaClass = testClass(self)
    end
    
    function Script:Test(data)
    	if data ~= nil then System:Print(data) else System:Print("Variable data is nil!") end
    end

    The "exampleScript.lua" Script:

    function testClass(script)
    	local container = {}
      
    	function container:CallMeFromAnywhereToSendSomething()
      	  self:SendSomething(script.dataToSend)
      	end
      
    	function container:SendSomething(sendData)
    	   if sendData ~= nil then
    	      script.data = sendData
    	   end
    	   if script.data ~= nil then System:Print("Sent my data!") script:Test(script.data) end
    	end
      
      	return container
    end
      	

    Addition:

    I was able to work around this issue by simply checking if the variable is nil, or not (I actually need/do stuff with the "data" variable in my actual script), but still I am confused. Maybe you can help me out. If you find other mistakes, or have improvement suggestions for my "Class" system please tell me. Thanks for reading :) 

  6. Hi Jorn. That sounds like a good idea. But I would appreciate if you could get a little bit more into detail.

    I would store your UI in an order list based on rend priority. Every time you create an element you add it to this list and give it a priority index.

     

    How to outsource my UI elements, or how to add them to the "list" and where do I actually render all my elements then? I cant get a clear idea how to realise this by my own sorry :D. I am no expert in lua coding.

  7. Hey guys,

     

    I was searching the forums for a releated subject, but I couldnt find one, but I could imagine there is one, if so I am sorry to post the same topic again happy.png

     

    So I am currently trying to come up with a way to handle diffrent objects rendering in the right order. What solutions have you for this problem.

     

    For example: I have a trading menu, but my cursor is rendered behind the inventory slots and buttons rendered by the NPC Trader entity. (elements of my trading menu are rendered by two diffrent entities (Player and NPC Trader))

     

    I was thinking about something where you can set a variable "renderPriority" which indicates in which order objects are rendered. So if render Priority is 1 those objects "PostRender" function is called before all the others, then come entities with priority 2,3 and so on. Thats the point I am stuck sad.png . How to make the other PostRender functions "wait" unitl the PostRender function of an specific entity is finished.

     

    This I a problem I occured pretty often and havent found a solution yet, I mean that you control the order entities call functions like UpdateWorld() or PostRender(). Would really appreciate if somebody can come up with an idea smile.png

  8. Hi,

     

    I just found a little, but kind of frustrating bug (was frustrating to find it out ^^). If you load an prefab, its children's "Start" functions were not being called in earlier version of Leadwerks, this is what has been fixed fortunately. BUT the system, or whatever you wanna call it, skips the entities, which are children of an entity which has NO script attached. The fix is to attach an script to every entity of your prefab so it does not skip any of your child's. I hope this helps and gets fixed soon.

     

    MadMorra

    • Upvote 2
  9. Hi guys,

     

    I searched the forum a bit and found out that other people had the same issue as I have now. You maybe know that if you have a key check (like window:KeyHit() or window:MouseHit()) in multiple scripts then only ONE of the works as expected. I read that its because Leadwerks sets the hit check value to false right after you checked it. However I tried to find a solution for this, by making a "class" where I call all keychecks, unfortunately the problem remains, maybe you can help me? What have you come up with? Thats my attempt:

     

    Thats the class script:

    function KeyCheck(script)
    local key = {}
    
    function key:MouseClicked(command)
    if command == "Left" then
    return window:MouseHit(1)
    elseif command == "Right" then
    return window:MouseHit(2)
    end
    end
    return key
    end
    

     

     

    These are two test scripts:

    import "Scripts/+Morra Scripts/System/KeyCheck.lua"
    local keyCheck
    function Script:Start()
    self.loadClass = KeyCheck
    keyCheck = self:loadClass()
    end
    function Script:UpdateWorld()
    if keyCheck:MouseClicked("Left") then System:Print("Test1") end
    end
    

     

    import "Scripts/+Morra Scripts/System/KeyCheck.lua"
    local keyCheck
    function Script:Start()
    self.loadClass = KeyCheck
    keyCheck = self:loadClass()
    end
    function Script:UpdateWorld()
    if keyCheck:MouseClicked("Left") then System:Print("Test2") end
    end
    

     

    I only get printed "Test1", due to this script seems to be called faster than the second one.

  10. Why can't you make a table of all needed data and loop through it to save each table key and value into file?

    Remember that these two lines refer to the same variable:

    
    

    myTable.abc

    myTable["abc"]

     

    Try something like this:

    
    

    for k,v in pairs(myTable) do

    stream:WriteLine(k.."="..v)

    end

    This way you will get a file like this:

    health=35

    armor=20

    magic=110

     

    To load this data into the game you need to read each string, separate it by "=" symbol and use left part as key and right as value.

    
    

    data={}

    while (not stream:EOF()) do

    local s = stream:ReadLine()

    local i = string.find(s,"=")

    local k = string.sub(s,1,i-1)

    local v = string.sub(s,i+1)

    data[k]=v

    end

    I haven't actually tried this code, so there can be mistakes.

    I believe you won't even need to convert value from string to number, it should be converted automatically if used in calculation. But you can also use tonumber function http://www.lua.org/manual/5.1/manual.html#pdf-tonumber

     

    You can also use string value to access global table itself because every global variable is an element of _G table. These two lines also refer to the same variable:

    
    

    myT.a

    _G["myT"]["a"]

     

    So you can make a header in your save file like this:

    [player]

    health=10

    magic=20

     

    And when you read a string that starts with "[" you can use it as a name of table which you are going to fill with data.

    
    

    if string.sub(s,1,1) == "[" then

    local tableName = string.sub(s,2,string.len(s)-1)

    ...

    _G[tableName][k]=v

     

    Thanks I definetly learnt something new about lua smile.png. I always wondered if it is possible to get a variable by its name per string. However your solution sounds very good, I will try that out for my save script smile.png. The problem I had, was that I needed to also access an element within the table and I struggled figuring out a way to search for a keyword within the file. So for example in the player save table (say there is position, health, rotation, current level etc) I just want to overwrite the healt value.

     

    But I have a question. What does string.sub exactly do?

  11. Hi Leadwerkers smile.png,

     

    Currently I am figuring out what would be the best way to save my game. What options there are for saving a table or varibles in general, and what options have you come up with?

     

    What I am working on at the moment was, to write a savedata table into a file like this and call it back with "dofile":

     

    return
    {
    someData = "Test";
    someOtherData = "Tes2t";
    }
    

     

    But this method is pretty tricky, not only have do you have to convert the variables into strings to save them, but it also is complicated and I think its no clean and fast solution because you have to work with the stream and filesystem command and "manually" write your data into a lua file.

    There is the System:SetProperty() command, but there you only can save strings as well. Are there any other commands Leadwerks offers? Another engine I worked before had a save command, where you can save any lua variable in (tables, strings, numbers everything) and then call it back.

     

    So tell me your attempt, what have you come up with? I want a system, where I just say: Save that variable and load that variable back on demand. If leadwerks does not offer such function itself I would be very thankful if you can link me tutorials, ideas or anything else which helps me building my own savesystem.

     

    Sorry if the english is not perfect biggrin.png

     

    Phoenix

  12. Hi there,

     

    I have a problem, maybe you guys can help me. I will make it quick. Following is what I have (just an example):

     

    function Script:Start()
    FileSystem:CreateFile("Data/Save Data/someData.lua")
    self.stream = FileSystem:WriteFile("Data/Save Data/someData.lua")
    end
    function Script:UpdateWorld()
    --I created this to find the error and to test it out
    if window:KeyHit(Key.K) then
    self.stream:WriteLine("Some text goes here")
    System:Print("It should work!")
    end
    end
    

     

    So I get printed "It should work!" AND the file gets created, but I can click "K" as often as I want, the text which should be written does not show up in the file. I need this to save data for my game. Whats the mistake. I noticed, that sometimes it gets written, after I close the application, but sometimes is has also been written while "ingame", but mostly it doesnt, especially with the scenario you can see above. Anyways this stream:WriteLine() seams to behave very akward. Further then solving my problem, what are your solutions for saving massive, or not so massive data (object positions, player position, npc states etc)?

     

    Thanks for your answers!

     

    EDIT: Just checked the data file again, and now the data is written a hundred times??? But I triple check if it gets written after I pressed "K". The problem is I need the file to be written immediately, because I grab the file again with dofile (I normally write code into the file that gets called (a simple "return" and some data))

  13. I think there actually is a prefab script for this. Search the project folder and go to Scripts, there should be a third person player controller. Without offending, and it is possible, but if you can't even code a third person controllr in Lua and or C++ I fear you won't be able to create a Tomb Raider game. You can learn but its pretty hard just saying.

  14. Hmm, thanks for your answers, so it seems to be a bug. Thats pretty ugly actually. So I now need to find I way to work around this.

     

    @Genebris your solution sound interesting, but as I am no master at coding, I don't understand that line of code you sent me. Whats that "main.system" part at your function? And what does entity.script,a,b,c? I am a little bit confused. However I think I can find my own solution for that. Maybe I write a small class for that I can import, which calls the start function of all of an entites children.

  15. Hi Leadwerkers,

     

    I have a problem. I would like to load my player prefab file, when the map loads and put it to a specific position. So I created a script for that. It loads my player prefab on start. The problem is, the Start function of its entities does not get called. I was able to fix it in a way but I still have a porblem. I told my main player script to call the Start functions of every childs script. The problem is some childs have childs aswell, and this child have other childs and so on. So why do the Start functions not work if I load a Prefab of my player which has many childs? Is there any fix? Suggestions? Am I doing something wrong? Or how to access every! child, and the childs of the childs etc of a singel entity, to then call the start function. I could make a ridiculous amount of loops, but thats pretty unefficent and stupid.

     

    Thanks for the help,

     

    Mad Morra

  16. Hi guys,

     

    I get some weird behavior with my project. Maybe it was not the best idea to update my project files, but since the 4.2 beta update I get the attached crash screen, when I start my game with debug mode. When I start it normally, then it crashes sometimes and somethimes not, which is very weird. I also had to change some of my code, which worked before the update. Were there any syntax changes or is there any documentation, if the update changes some major stuff, regarding the lua coding? I think this is really annoying and makes Leadwerks not very enjoyable to use sad.png. Can you help me? Maybe I am doing something wrong.

     

    post-17271-0-88376600-1483043453.png

  17. What would be the best way to get a specific type of entity in an area? I am currently working on my AI and I want it to search a weapon, if it has no at the moment. So I want it to check its sourrounding for a weapon.

    Whats the best way to do it. Or I could need it that my AI can check for enemies in its sourrounding.

     

    I thought of getting all entities in the scene (world) check their distance to the AI and if it is smaller then the AIs sense radius, then it checks them for the type (for example if it is a weapon or not) and returns to the AI.

     

    So whats the best way to get specific entities in a defined area (for example around a NPC)? Any ideas on how to make it better then the concept I have?

×
×
  • Create New...