Jump to content

bansama

Members
  • Posts

    64
  • Joined

  • Last visited

Posts posted by bansama

  1. Sorry for another question which probably has a dead easy answer, but we have to learn somewhere right?

     

    I'm trying to display text on screen for a specific time. Basically, when I "use" an object, I want to display related text for a seconds. I was hoping some kind of while loop to count down the specified amount of time would work, but it had less than desirable results. FPS drops, text not displaying, etc. Any suggestions on what I should be doing?

     

    function Script:Use(context)
    self.Used = "1"
    end
    
    function Script:PostRender(context)
    if self.Used == "1" then
    local font = Font:Load("Fonts/arial.ttf", 12)
    App.context:SetFont(font)
    if self.ObjectDescription ~="" then
    local DisplayTime = 0
    while DisplayTime < self.DisplayTimeMax do
    App.context:SetBlendMode(Blend.Alpha)
    context:DrawText(self.ObjectDescription, 102, 22)
    App.context:SetBlendMode(Blend.Solid)
    DisplayTime = DisplayTime + 1
    end
    end
    self.Used = "0"
    end
    end

  2. I've been messing around with trying to make a light switch, which I've managed to accomplish in a rather rudimentary fashion by using entity:show() and hide(). In doing so, I've noticed that the level of light when no lights are active is a bit too bright.

     

    How would I go about making it as near to pitch black as possible?

  3. Given that you can specify privacy settings, I see no problem with people sharing builds with friends via workshop. It's also better than dropbox as it doesn't require additional downloads. Besides that, the workshop is set up to make updating easy for all involved, Drop box and similar don't do that.

     

    I will add that the FAQ Josh posted mentions Workshop being a good way to get games on Steam without having to go through Greenlight. So surely, people who don't own Leadwerks being able to download items published as "Games" would be good for all anyhow.

  4. I ended up looking into this more and seem to have found a solution that works well enough.

     

    First I added this at the start of the SwiningDoor script. The default value is what has worked best for me so far.

     

    Script.closeoffset=1.3--float "Close offset"
    

     

    And then making the very simple change of:

     

    self.joint:SetAngle(self.closedangle)

    to

    self.joint:SetAngle(self.closedangle-self.closeoffset)

     

    As shown below:

     

    function Script:Close()--in
    if self.enabled then
    if self.openstate then
    self.openstate=false
    if self.loopsource then
    self.loopsource:Release()
    self.loopsource=nil
    end
    if self.closesound then
    self.entity:EmitSound(self.closesound)
    end
    self.joint:SetAngle(self.closedangle-self.closeoffset)
    self.component:CallOutputs("Close")
    end
    end
    end
    

  5. As a follow on from this topic: http://www.leadwerks.com/werkspace/topic/10226-where-can-i-find-this-example-map/

     

    I now have sliding doors set up. These I can now make without a problem. But in doing so I have noticed something which I think is caused by something in the sliding door script itself, but I have no idea what exactly.

     

    The problem is that once a door has been opened (I'm using the manual activate set to true, with closing delay set to 0) when you close it, it always ends up a tiny degree off from its starting point. It's as if the script is ending before the very last degree of movement so it cannot come to rest at its original position.

     

    To be honest, I doubt it's something most would notice unless specifically looking for it, but it is a little annoying nonetheless.

     

    Any ideas on what's going on and how it could be fixed?

  6. Glad to hear you got it working. I will add though that depending on the size and position of your door, you'll want to mess around with which actual offset to use (x, y, z) and try sizes that are smaller than 1.0. I found that for a door with a width of 128 cm, an offset of 0.7 works rather well.

  7. Here's what I did:

     

    1 - Loaded up the tutorial map 03-Doors and saved it with a new name. That way any mistakes won't render the tutorial map useless should it be needed in the future.

     

    2 - Using the second set of doors, I replaced the sliding door script for both doors with the swinging door one.

     

    3 - Opened up the Flowgraph Editor and made sure the BoXTrigger:CollisionTrigger Collision() option was linked to the slidingdoor_left:SwingingDoor Open() and slidingdoor_right:SwingingDoor Open() options. If those don't exist in the Flowgraph Editor you may need to drag the door objects in to the Flowgraph Editor screen.

     

    4 - Set the values in the script for slidingdoor_left: Offset 0.0, 0.0, 1.0; Pin 0.0, 1.0, 0.0

     

    5 - Set the values in the script for slidingdoor_right: Offset 0.0, 0.0, -1.0; Pin 0.0, -1.0, 0.0

     

    The trick will be getting the right combination of values to have any door opening on the side and in the direction you want.

     

    Hope that helps.

  8. if entity:GetKeyValue("name") == "Player" then

    System:Print("Found Player")

    self:PlayerPosition(entity)

    end

     

    But you'll notice how much easier things are without globals in this case. Just call the function from the collision passing in the entity when it's the player. There is no need for the global and in fact having the global caused more typing and more things that can go wrong.

     

    That did it. Now I see where I was going wrong. As the function appears to be processed without being called I had not thought that calling with self:PlayerPosition(entity) was required. Your comment about globals though is something I'd like to clarify. Using local before the variable name ensures it's not a global, right? If such a variable is passed with self:FunctionName (variable) does it remain non-global?

  9. Tell us the exact error you are getting and on what line. I'll leave this site open all day so send me an IM on it and if I'm on I'd be more than happy to help you in real-time.

     

    I've put some of my old code back in for now, which has gotten rid of the errors. However, what I am trying to do is fetch the player on collision. This I've now done.

     

    if entity:GetKeyValue("name") == "Player" then
    System:Print("Found Player")
    PlayerEnt = entity
    System:Print(PlayerEnt)
    return PlayerEnt
    end
    

     

    The system print shows it's found the player entity.

     

    I was hoping the return would allow that to be picked up by another function in the same script.

     

    function Script:PlayerPosition(PlayerEnt)--arg
    
    System:Print("Testing...")
    System:Print(PlayerEnt)
    System:Print("...End testing")
    
    end
    

     

    This system print shows that PlayerEnt has not been passed as the output is 0x00000000 and not the address found on collision.

     

    I know I don't need to do any of this. I could just handle everything within the function handling collision, but I really would like to know how to pass PlayerEnt from one function to another as I'm sure it will help in the future with other things.

     

    Right now this PlayerPosition function is where I'm testing all the coordinate stuff, ie. breaking it down into x, y, and z (which again, I've managed). The only thing holding me back with this current approach is passing that PlayerEnt between the functions.

     

    Also, thanks for the offer of helping via the IM function (I assume that's the bar at the bottom of the site, right?) if you're still around in a couple of hours, I'll take you up on that. I just need to get the children in bed first.

     

    @YouGroove Yes, I lack the knowledge I need to do what I'm trying to do, hence the topic. I appreciate your examples though they have provided some food for thought.

  10. Are you actually setting the keyvalue to the entities you want to find? The leadwerks does not actually set this for you, it needs to be set in script. The fpsplayer already has this in the script.

     

    A good point I will bear in mind. But for now it's the player I am trying to work with. The collision function finds the player, but how do I then pass the player as found by the collision function to a different function in the same script?

  11. You can do this by checking a key value. Let's say you named your player entity "Player". This gives it a "name" key of "Player". So in your collision event you check if entity:GetKeyValue("name") == "Player".

     

    In theory, this all makes perfect sense. In practice, I'm still getting the "attempt to index global/local 'entity' (a nil value)" errors. Which again brings me back to the question, how do a I pass variables between scripts and functions?

     

    For example if I try adding the following function to the collision script template:

     

    function Script:PlayerPosition(entity)--arg
    if entity:GetKeyValue("name") == "Player" then
    self.PlayerTarget = entity
    return self.PlayerTarget:GetPosition():ToString()
    end
    end

     

    I get an error that makes it clear the function cannot find the entity.

     

    As I said when I first made this topic, this is something that was so elementary easy in PHP that I just can't work out why I cannot do it in Lua and it is driving me completely crazy and leaving utterly frustrated. So I would really appreciate some concise help with actual example code so I can work out what is wrong with my own code.

     

    As YouGroove said, making errors and learning from them is good. But only if someone can help point out why it's an error and how to fix it. Otherwise, you may just end up in an infinite loop of errors and learning nothing. That's why we need teachers, and why I would really appreciate help with this.

  12. @YouGroove Thanks, I'll have a look at that in a little bit.

     

    What is your final goal here?

     

    To recap, I want to be able to reference coordinates and rotation of the player entity so I may use this information when moving the player around on a collision event inspired by the teleport tutorial found on YouTube (which, if I'm not mistaken, was uploaded by yourself?)

     

    I would prefer to be able to do this without needing to be dependent on the flow graph editor due to it wiping links. Which, so far, I still have not determined the cause of. And as I mentioned earlier, I don't want to need to loop through entities to find the player each time, when doing that once should theoretically suffice.

     

    I did have this working with the code above in App.lua, but based on your previous comments, I'm now trying to to do the same without needing to alter App.lua.

     

    So in short, I am currently trying to set up a pivot that will locate the player entity so that I may reference that entity later without having to loop through all entities to find it each time (and without needing to link to player to specific entities in the flow graph editor each time).

  13. Once again, thanks for the replies. I've been busy with work thus have had no time to revisit this for while. But I have some free time again now for a few days and with that time, another question!

     

    Am I right in that self.whatever can only be used within a function? If I try it outside of a function, I get the usual error about attempting to index a nil global. If this is so, then I'll need to slightly tweak my current code that I put in App.lua so that it's now a function. I'm also going to try moving that out of App.lua and attaching it to a pivot as its own script.

     

    EDIT: So apparently I can't get that to work either. Using the following as a script attached to the pivot:

     

    --Set player entity
    function Script:SetPlayerEntity()
    -- Locate the player entity
    for x=0,App.world:CountEntities()-1 do
    entity = App.world:GetEntity(x)
    entInfo = entity:GetKeyValue("name")
    if entity:GetKeyValue("name") == "Player" then
    self.EntPlayer = App.world:GetEntity(x)
    System:Print(self.EntPlayer)
    end
    end
    setPlayerEntFlag = true
    end
    
    if setPlayerEntFlag ~= true then
    Script:SetPlayerEntity()
    end

     

    And then trying to reference it in a different script with:

     

    self.PlayerTarget = LocatePlayerEntity.EntPlayer

     

    I get the usual "attempt to index global 'LocatePlayerEntity' (a nil value)" error =S

     

    EDIT 2:

     

    A final edit as this is driving me crazy again.

     

    If I modify the end of the above script which is attached to the pivot so that it is:

     

    if setPlayerEntFlag ~= true then
    Script:SetPlayerEntity()
    end
    System:Print ("Hello")
    System:Print(self.EntPlayer)
    

     

    Then the first System: Print works, and I see Hello being output, but the second throws up the same self related error. Which pretty much tells me that self is not doing what I need, or I simply have no clue as to how it's supposed to work (which is very likely). I've tried Googling for information on this and can find nothing helpful that is written in a manner I understand. So I would appreciate some help with understanding why this isn't working. This is both with and without "return self.EntPlayer" being added to the function.

  14. I know it's been a while, but I have another question...

     

    While I've made some progress, I'm still not sure how to reference a variable set in one script from another script without using the flow editor or setting it as a global. For example, I know have the following in App.lua:

     

     --Set player entity
    if setPlayerEntFlag ~= true then
    -- Locate the player entitiy
    for x=0,App.world:CountEntities()-1 do
    local entity = App.world:GetEntity(x)
    local entInfo = entity:GetKeyValue("name")
    if entity:GetKeyValue("name") == "Player" then
    EntPlayer = App.world:GetEntity(x)
    System:Print(EntPlayer)
    end
    end
    setPlayerEntFlag = true
    end

     

    This locates the player entity and as the system:print line shows, it does indeed locate it. This allows me to use the player without having to loop to it each time and allows me to use it without needing to link it in the flow editor (as that still randomly wipes such connections -- I can't work out when or why though, so have yet to report as a bug).

     

    So I can then reference the player entity in another script I use:

     

    self.PlayerTarget = EntPlayer

     

    In the other script. This currently works because EntPlayer is global. But I'd like to know how to interact with it when it's a local variable. I tried App.EntPlayer, script.App.EntPlayer, and variants thereof, but always get the "global is a nil value" error. So my question is, what am I missing?

  15. So another evening spent on this at last. But another evening where I feel I'm hitting my head against a brick wall.

     

    Right now, I'm pointing scripts to the player entity with Script.PlayerTarget = nil --entity and dragging the Player to the related box in the editor. But when I switch between projects, etc., this has often seems to be wiped out. So I need to keep setting it. It's frustrating, so I figure I should just tell the script directly that I want it to work with the player entity.

     

     for x=0,App.world:CountEntities()-1 do
    local entity = App.world:GetEntity(x)
    entInfo = entity:GetKeyValue("name")
    System:Print(entInfo)
    end

     

    As I think I've said before, the above works to output entity names to the Output window. This gave me the idea to use GetEntity() to specify the name directly with: self.PlayerTarget = App.world:GetEntity(Player)

     

    But this just throws back an error. I can find no documentation on GetEntity.

     

    Is there a simple way to state directly in a script that variable X should equal entity y, without using a loop like the above to search for it? [self.PlayerTarget = entity:GetKeyValue("Player") didn't seem to work either]

     

    On an unrelated note, I've noticed that the way in which I was outputting coordinates to the screen no longer works unless I'm in debug mode.

     

    function Script:PostRender(context)
    local font = Font:Load("Fonts/arial.ttf", 12)
    App.context:SetFont(font)
    App.context:SetBlendMode(Blend.Alpha)
    if self.Text ~="" then
    context:DrawText("Current output is " .. self.Text, 102, 22)
    end
    App.context:SetBlendMode(Blend.Solid)
    end

     

    This used to output text when "Running" the game but now only does so when "Debugging". Did something change?

     

    EDIT: Actually come to think of it, I don't recall seeing the FPS counter that usually displays either. Is there a hotkey toggle for that which I may have accidentally pressed?

×
×
  • Create New...