Jump to content

gordonramp

Members
  • Posts

    398
  • Joined

  • Last visited

Posts posted by gordonramp

  1. This sounds great i was attracted to leadwerks from using lua with shiva, they provide a great demo level with basic documentation on its creation, well worth checking out. Being an artist / animator i'm sure learning about programing has contributed to many of my grey hairs. Seeing a few practical examples implemented and explained in a working environment can be all thats needed to get one started.

    Yes, and it's no shame to copy and paste in order get something working. Like an artist who uses recycled materials to produce great works of art. It's just a way of accomplishing an end. Also some Language producers encourage copy and paste. The Gamecreators are in this category. They have a Snippets Forum, a Code Base and a Newcomers Corner. They understand how important it is to get people into their world and way of thinking. I remember laughing when I bought Dark Basic Classic and some example games accompanied it with the suggestion that they be hacked and torn apart so that purchasers could get the hang of how to do things. I think that was a great attitude. :lol:

  2. I think it's a cop-out to expect new 2.3 users to learn how to code the Leadwerks Engine in Lua by looking at old C++ Tutorials. What's needed are working examples in Lua. The 'Getting started with Lua Script' Tutorial is a good example of how they need to be although even that digresses into C++ at the end. Have a look at the number of posts on the Lua Forum compared to the C++ forum.. People are desperately trying to understand just the basics of the LE script only to find there is almost no documentation, only helpful Lua coders. Once again, we have the 'one man band' syndrome where promised Tutorials just aren't appearing because the one man is looking in other areas.

  3. i can do that right now by commenting out the CreateFramework()... it will load the new scene into the existing scene... so it appears that CreateFramework is freeing everything...

    Macklebee, did you mean.. 'comment out FreeFramework(fw)' because when I do that for the second scene it loads and exits without an error. My only hope is that everything is in fact being deleted by CreateFramework() or Loadscene(), so that there is no performance hit down the track.

     

    Update: There appears to be no performance loss when switching from scene to scene apart from the altering size of the scene. On to the next conundrum..Thanks :D

  4. Lumooga,

    You may be correct but if I use the 2.3 'train' and 'tunnels' .sbx maps then the same thing occurs. The code has to be run from outside of the Scripting Editor for the Error to occur. As it would in a Game situation. :P

  5. Here is the complete working script.. It changes the Scene. Paste this into the Script Editor, Save it and close the Script Editor then double-click the saved file to run it. It runs Ok but when I move to another scene by pushing (F) then exiting, the Error occurs.

     

    require("Scripts/constants/collision_const")
    require("Scripts/constants/engine_const")
    require("Scripts/LinkedList")
    require("Scripts/filesystem")
    require("Scripts/math/math")
    
    function round(num, idp)        
    return tonumber(string.format("%." .. (idp or 0) .. "f", num))
    end
    
    function playercreation() --Function to create a player controller and set camera variables
    controller=CreateController(1.8,0.45,0.25,45)
    controller:SetCollisionType(COLLISION_CHARACTER,0)
    controller:SetMass(10)
    if standalone==1 then        
    controller:SetPosition(Vec3(-20,1,-5))
    else        
    controller:SetPosition(fw.main.camera.position)
    end
    camerapitch=fw.main.camera.rotation.x
    camerayaw=fw.main.camera.rotation.y-110
    camera = fw.main.camera
    end
    
    BLEND_NONE=0
    BLEND_ALPHA=1
    
    if fw==nil then --we are not in Editor        
    RegisterAbstractPath("")        
    Graphics(1680,1050)        
    fw=CreateFramework()        
    scene=LoadScene("Maps/terrain_base.sbx")        
    scene:SetCollisionType(COLLISION_SCENE)        
    TFilter(1)        
    AFilter(4)        
    standalone=1
    end
    
    dx=0.0
    dy=0.0
    camerapitch=0.0
    camerayaw=0.0
    move=0.0
    strafe=0.0
    
    playercreation()--Call the controller function
    
    HideMouse()
    MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
    
    --position
    function DrawHUD(contr)        
    SetBlend(BLEND_ALPHA)        
    DrawText("position: "..round(contr.position.x,1)..","..round(contr.position.y,1)..","..round(contr.position.z,1),1,FontHeight()*1)        
    --DrawText("rot: "..round(contr.rotation.x,3)..","..round(contr.rotation.y,3)..","..round(contr.rotation.z,3),1,FontHeight()*6)        
    SetBlend(BLEND_NONE)
    end
    
    --main function
    while KeyHit(KEY_ESCAPE)==0 do        
    jump=KeyHit(KEY_SPACE)*6.0        
    if controller:IsAirborne()==1 then jump=0 end        
    local time = AppTime()/3200.0        
    local frame = time*(179.0-96.0)+96.0        
    frame=Clamp( frame, 96, 179 )        
    
    --Camera look        
    gx=Round(GraphicsWidth()/2)        
    gy=Round(GraphicsHeight()/2)        
    dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())        
    dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())        
    MoveMouse(gx,gy)        
    camerapitch=camerapitch+dy        
    camerayaw=camerayaw-dx        
    camerapitch=math.min(camerapitch,90)        
    camerapitch=math.max(camerapitch,-89.99)       
    fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)        
    movespeed=4        
    movesmoothing=10        
    if controller:IsAirborne()==1 then                
    movesmoothing=200        
    end 
    
    --Player movement        
    move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)        
    strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)        
    
    --Update controller        
    controller:Update(camerayaw,move,strafe,jump,40,10)        
    fw:Update()        
    
    --Position camera        
    camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)        
    time=AppTime()        
    
    fw:Render()
    
    DrawHUD(controller) 
    
    --new Framework---------------------------------------------------------------------------------------------------
    
    if KeyHit(KEY_F)==1 then 
    FreeFramework(fw)
    fw=CreateFramework()
    SetGlobalObject("fw",fw)        
    scene=LoadScene("Maps/terrain_base2.sbx")
    playercreation()-- call the controller function again to create new controller and camera variables
    end
    
    ------------------------------------------------------------------------------------------------------------------
    Flip(0)
    end
    controller:Free()
    
    ShowMouse()

  6. Aggror,

    Ok, here is the basic Framework fp code that I am building on. It's on this code that I am trying lots of variations.. you should be able to load any map into it.. Note that the first scene is deleted and the new one loaded at the bottom of the main loop.

     

    require("Scripts/constants/collision_const")
    require("Scripts/constants/engine_const")
    require("Scripts/LinkedList")
    require("Scripts/filesystem")
    require("Scripts/math/math")
    
    function round(num, idp)        
    return tonumber(string.format("%." .. (idp or 0) .. "f", num))
    end
    BLEND_NONE=0
    BLEND_ALPHA=1
    
    if fw==nil then --we are not in Editor        
    RegisterAbstractPath("")        
    Graphics(1680,1050)        
    fw=CreateFramework()        
    scene=LoadScene("Maps/terrain_base.sbx")        
    scene:SetCollisionType(COLLISION_SCENE)        
    TFilter(1)        
    AFilter(4)        
    standalone=1
    end
    
    dx=0.0
    dy=0.0
    camerapitch=0.0
    camerayaw=0.0
    move=0.0
    strafe=0.0
    
    --Create a player controller
    controller=CreateController(1.8,0.45,0.25,45)
    controller:SetCollisionType(COLLISION_CHARACTER,0)
    controller:SetMass(10)
    if standalone==1 then        
    controller:SetPosition(Vec3(-20,1,-5))
    else        
    controller:SetPosition(fw.main.camera.position)
    end
    camerapitch=fw.main.camera.rotation.x
    camerayaw=fw.main.camera.rotation.y-110
    HideMouse()
    MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
    
    local camera = fw.main.camera
    
    --position
    function DrawHUD(contr)        
    SetBlend(BLEND_ALPHA)        
    DrawText("position: "..round(contr.position.x,1)..","..round(contr.position.y,1)..","..round(contr.position.z,1),1,FontHeight()*1)        
    --DrawText("rot: "..round(contr.rotation.x,3)..","..round(contr.rotation.y,3)..","..round(contr.rotation.z,3),1,FontHeight()*6)        
    SetBlend(BLEND_NONE)
    end
    
    --main function
    while KeyHit(KEY_ESCAPE)==0 do        
    jump=KeyHit(KEY_SPACE)*6.0        
    if controller:IsAirborne()==1 then jump=0 end        
    local time = AppTime()/3200.0        
    local frame = time*(179.0-96.0)+96.0        
    frame=Clamp( frame, 96, 179 )        
    
    --Camera look        
    gx=Round(GraphicsWidth()/2)        
    gy=Round(GraphicsHeight()/2)        
    dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())        
    dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())        
    MoveMouse(gx,gy)        
    camerapitch=camerapitch+dy        
    camerayaw=camerayaw-dx        
    camerapitch=math.min(camerapitch,90)        
    camerapitch=math.max(camerapitch,-89.99)       
    fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)        
    movespeed=4        
    movesmoothing=10        
    if controller:IsAirborne()==1 then                
    movesmoothing=200        
    end 
    
    --Player movement        
    move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)        
    strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)        
    
    --Update controller        
    controller:Update(camerayaw,move,strafe,jump,40,10)        
    fw:Update()        
    
    --Position camera        
    camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)        
    time=AppTime()        
    
    fw:Render()
    
    DrawHUD(controller) 
    
    --new Framework---------------------------------------------------------------------------------------------------
    
    if KeyHit(KEY_F)==1 then 
    FreeFramework(fw)
    fw=CreateFramework()
    SetGlobalObject("fw",fw)        
    scene=LoadScene("Maps/terrain_base2.sbx")
    end
    
    ------------------------------------------------------------------------------------------------------------------
    Flip(0)
    end
    controller:Free()
    
    ShowMouse()

     

    Yes, I have attempted any of the suggestions on this thread.

  7. Thanks guys, no improvement, I get the distinct impression that I'm not structuring the code correctly. This is just the sort of topic that really needs a tutorial, changing scenes is basic to any game. :rolleyes:

  8. Rick,

    When I try to reset the controller with

    controller:SetPosition(Vec3(-20,1,-5))

    I get an 'Access Violation'.

     

    Aggror,

    If I place that code within the main loop, nothing happens at all.

  9. Aggror,

    That may be a solution but I'm currently unable to implement it within the Framework. I've tried all sorts of things. Like I said, the old scene removes and the new scene loads but but I'm stuck underneath it without movement.

     

    VicToMeyeZR,

    No change when I flip it.

    :)

  10. if KeyHit(KEY_F)==1 then 
    FreeFramework(fw)
    fw=CreateFramework()
    SetGlobalObject("fw",fw)        
    scene=LoadScene("Maps/newscene.sbx")

    Using the fpscontroller.lua code..

    This deletes the old scene and loads the new. I have mouselook but seem to be stuck under the new scene with no movement.

  11. In a FPController scene, how can I detect when I have touched or collided with a particular object so that an event can take place? Another way to describe it is.. How would I go about creating a hotspot?

  12. Does anyone know what the Lua code for Full Screen is?

    In BlitzMax it is..

     

    Graphics(screenwidth,screenheight,Int(AppSetting("fullscreen"))*32,60,0)

    but there's nothing in the documentation yet for Lua.

  13. Here is some example code which writes and reads data to and from a text file. Open the ScriptEditor in the LE.SDK folder and place this code in it. Run it and a text file (my.txt) will be created in the same folder. Then the code will read the text file and write the contents to the screen. Note: If the Output content is changed, then the previous content in the text file is overwritten.

     

    --Register abstract path
    RegisterAbstractPath("")
    
    --Set graphics mode
    if Graphics(1024,768)==0 then
    Notify("Failed to set graphics mode.",1)
    return
    end
    
    world=CreateWorld()
    if world==nil then
    Notify("Failed to initialize engine.",1)
    return
    end
    
    gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),1+2+4+8)
    
    camera=CreateCamera()
    camera:SetPosition(Vec3(0,0,-2))
    
    light=CreateSpotLight(10)
    light:SetRotation(Vec3(45,55,0))
    light:SetPosition(Vec3(5,5,-5))
    
    material=LoadMaterial("abstract::cobblestones.mat")
    
    mesh=CreateCube()
    mesh:Paint(material)
    
    ground=CreateCube()
    ground:SetScale(Vec3(10.0,1.0,10.0))
    ground:SetPosition(Vec3(0.0,-2.0,0.0))
    ground:Paint(material)
    
    light=CreateDirectionalLight()
    light:SetRotation(Vec3(45,45,45))
    
    ---------------------------------------------------------
    --Create a text file and write data to it
    
    io.output(io.open("my.txt","w"))
    io.write("21")
    io.close()
    
    ---------------------------------------------------------
    
    while AppTerminate()==0 do
    
    mesh:Turn(Vec3(AppSpeed()*0.5,AppSpeed()*0.5,AppSpeed()*0.5))
    
    UpdateAppTime()
    world:Update(AppSpeed())
    
    SetBuffer(gbuffer)
    world:Render()
    SetBuffer(BackBuffer())
    world:RenderLights(gbuffer)
    
    ----------------------------------------------------------
    --Open the text file and write it's context to the screen
    
    file = io.open("my.txt","r")
    for line in file:lines() do
    DrawText(line,0,20) 
    end
    file:close()
    
    -----------------------------------------------------------
    
    DrawText(UPS(),0,0)
    
    Flip(0)
    end

  14. I added this Lua into the LE example1 and it runs with no errors but no text appears on the screen. Anyone have a clue as to why?

     

    print(io.open("newinput", "w"))--write
    print(io.open("newinput", "r"))--read
    DrawText(newinput,0,10)--draw

     

    Update:

    Don't bother.. I get it.

  15. I know this as a major topic and I'm probably not the best one to bring it up but I will anyway because everyone is going to have to look at it sooner or later. Josh has posted an input console and I'm sure it's not the only one. Now what to do with the data from that and other sources. Starting with simple solutions.. Is it possible to write to a text file and also read it using Lua from the LE. I come from DBPro and in that language it is. It's also possible to write to the Windows Registry. Then there's Xml, and .ini files or purpose built 3rd-parties like sqlite3. So has anyone been exploring this and come up with any simple examples of using Lua to write and read data for use in the LE?

×
×
  • Create New...