Jump to content

Getting_Started_With_Lua AddHook Example


Davaris
 Share

Recommended Posts

I'm going through the Getting_Started_With_Lua.pdf and I just got up to the AddHook part and I can't get the DrawOverlay hook to work. Can anyone see what I am dong wrong?

 

 

 

require("scripts/constants/keycodes") 
require("scripts/hooks")

--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)) 


function DrawOverlay()

DrawText("DrawOverlay",0,50)

SetBlend(1) 
SetColor(Vec4(1,0,0,0.25)) 
DrawRect(100,100,GraphicsWidth()-200,GraphicsHeight()-200) 
SetColor(Vec4(1,1,1,1)) 
SetBlend(0) 
end 

AddHook("Flip",DrawOverlay)




while AppTerminate()==0 do 

if KeyHit(KEY_ESCAPE)==1 then 
	break 
end 

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) 

DrawText(UPS(),0,0) 
Flip(0) 
end

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

yeah works fine for me too.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

On mine it isn't showing the transparent red rectangle.

 

In the example just before it uses:

 

function FlipHook() 
SetBlend(1) 
SetColor(Vec4(1,0,0,0.25)) 
DrawRect(100,100,GraphicsWidth()-200,GraphicsHeight()-200) 
SetColor(Vec4(1,1,1,1)) 
SetBlend(0) 
end

 

and it works in that the red rectangle is visible. On the one I posted above, it doesn't work, even when I copied it to my SDK directory which is updated. So if it works for you guys it might be a bug.

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

 

and it works in that the red rectangle is visible. On the one I posted above, it doesn't work, even when I copied it to my SDK directory which is updated. So if it works for you guys it might be a bug.

 

 

I'd have thought it would be a bug if it had not worked for us, what are your system specs?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

seems you are not doing something right because i dont see how this could be a bug...

 

where is the lua file? wherever it is put it in the main SDK directory. Now drag it and drop it on the engine.exe. should work fine.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I just fixed it. I altered the compatibility mode to WinXP SP3 and now it works!

 

The SDK was in the Program Files (x86) directory, so I don't know why it did not properly.

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

I just fixed it. I altered the compatibility mode to WinXP SP3 and now it works!

 

 

Ok .. everyone stand down from Bug alert :blink:

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Just tried it and the Windmill still doesn't spin and the fire barrel behavior is unchanged: there is light and sound, but no visible particles for the fire or smoke. I don't know if Josh has updated those scripts though.

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

Josh hasn't updated the Windmill Lua script to work with the engine, but you can find here the updated Windmill Lua script:

http://leadwerks.com/werkspace/index.php?/tracker/issue-49-windmill-script-is-not-updated/

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

the firepit = fire barrel? if so, that one is updated and works just fine for me... does it work in the editor for you?

 

the windmill isn't updated (actually i think lumooja did it?)... and i dont think its actually even in the latest download since we went to singlestate lua...

 

perhaps you should try a clean download of the SDK?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

i dont think its actually even in the latest download

 

 

No its not, after I did a full fresh install it was not there.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

the firepit = fire barrel? if so, that one is updated and works just fine for me... does it work in the editor for you?

 

It works perfectly in the editor for some reason. :P

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

ok... i didnt expect your entire code :P what i am not seeing is the anything that integrates the lua to c++.. arent you missing this code somewhere:

//Set Lua variable
BP L=GetLuaState();
lua_pushobject(L,framework);
lua_setglobal(L,"fw");
lua_pop(L,1);

 

and off hand i dont see the framework being initialized...

 

unless of course thats all being handled in gamelib? :P

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

In GameLib this function is called:

 

 

void TGame::Initialize(int sx0, int sy0, int fullscreen)
{
scene.Initialize(sx0,sy0,fullscreen);
scene.game=this;
gamelib_callback=this;
luat.Create();									// create the LuaTools object
luat.SetScriptObject("fw",scene.framewerk);		// set the Lua variable fw

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

and where is this?

 

//Set Lua variable
BP L=GetLuaState();
lua_pushobject(L,framework);
lua_setglobal(L,"fw");
lua_pop(L,1);

 

I think this is it:

 

 

void LuaTools::SetScriptObject( const std::string& name, BP o )
{
int size = GetStackSize();
PushObject( o );
SetGlobal( name );
SetStackSize( size );
}

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...