Jump to content
Chris Vossen

Leadwerks 3 "How do I ____?" Questions and Answers

Recommended Posts

Hi, I'm getting the following error in lua; 'attempt to index global 'Map' (a nil value). sad.png

 

function App:Start()

--Set the application title
self.title="MyGame"

--Create a window
self.window=Window:Create(self.title,0,0,1024,768,Window.Titlebar+Window.Center+8)
--self.window:HideMouse()

--Create the graphics context
self.context=Context:Create(self.window,0)
if self.context==nil then return false end

--Create a world
self.world=World:Create()

--Load a map
return Map:Load("Maps\start.map")
end

 

Try: adding in an extra backslash

return Map:Load("Maps\\start.map")

Share this post


Link to post

How do i de-attach scripts from objects in the editor?

 

Thanks

Andy

 

In the Scene browser click on the object that has the script attached to it, right click on the script tab (example if the script is called animationmanager the tab will be called animationmanager) then chose delete.

 

post-5181-0-68472500-1362219299_thumb.png

Share this post


Link to post

Awesome handfull new shader smile.png

 

 

I have some problem to understand that bit of code :

 

function EnemyForEachEntityInAABBDoCallback(entity,extra)

if extra.goblinai.target==nil then

if extra~=entity then

if entity.player~=nil then

extra.goblinai.target=entity.player

end

end

end

end

 

What is goblinai ? the name of script file ?

target is the global variable in this script instance ?

 

Why having all that tests why not directly do :

extra.goblinai.target=entity.player

caus extra will always be an entity passed throught the function ?

Share this post


Link to post

A couple of Android queries:

 

1) Will it be possible to change the build target from the default to 4.x.x Jellybean for instance?

 

2) Will it be possible to incorporate the Google licensing api if required?

 

3) If needs be am I free to modify the android manifest?

 

Thanks.

Share this post


Link to post

Awesome handfull new shader smile.png

 

 

I have some problem to understand that bit of code :

 

function EnemyForEachEntityInAABBDoCallback(entity,extra)

if extra.goblinai.target==nil then

if extra~=entity then

if entity.player~=nil then

extra.goblinai.target=entity.player

end

end

end

end

 

What is goblinai ? the name of script file ?

target is the global variable in this script instance ?

 

Why having all that tests why not directly do :

extra.goblinai.target=entity.player

caus extra will always be an entity passed throught the function ?

 

Quick Answer: goblinai is the name of the script attached to the goblin entity. The declaration of target was actually a slip up on my part, it should have been declared at the top of the script as Script.target = nil.

 

This brings up a good point on how flexible Lua is (which can get you into trouble sometimes) since self.target is not declared anywhere, when something is assigned to it lua creates the variable on the fly. It will not be global because of the prefix "self".

 

Long Answer:

 

To fully understand this code you have to look at these two chunks of code:

 

--Check for a new target in the area
if not self.target then
if time-self.lastCheckForTargetTime>500 then
self.lastCheckForTargetTime=time
local position = self.entity:GetPosition(true)
local aabb = AABB()

aabb.min.x=position.x-self.sightRadius
aabb.min.y=position.y-self.sightRadius
aabb.min.z=position.z-self.sightRadius
aabb.max.x=position.x+self.sightRadius
aabb.max.y=position.y+self.sightRadius
aabb.max.z=position.z+self.sightRadius
aabb:Update()
self.entity.world:ForEachEntityInAABBDo(aabb,"EnemyForEachEntityInAABBDoCallback",self.entity)

if self.target then
self.entity:EmitSound(self.sound.attack[math.random(0,#self.sound.attack)])
self.currentState=self.state.chase
self.entity:Follow(self.target.entity,self.speed,self.maxaccel)
--self.entity:SetMass(self.mass)
self.followingTarget=true
end
end
end

 

and

 

function EnemyForEachEntityInAABBDoCallback(entity,extra)
if extra.goblinai.target==nil then
if extra~=entity then
if entity.player~=nil then
extra.goblinai.target=entity.player
end
end
end
end

 

Basically if the goblin does not have a target assigned an AABB (axis aligned bounding box) is created around the goblin with a height, width, and depth of the goblins sight radius.

 

self.entity.world:ForEachEntityInAABBDo(aabb,"EnemyForEachEntityInAABBDoCallback",self.entity)

 

The foreachentityinaabbdo function is then called on the newly created aabb. The call back function name "EnemyForEachEntityInAABBDoCallback" is passed in as parameter 2, this means that for every entity within the aabb the callback function "EnemyForEachEntityInAABBDoCallback" will be called. Finally parameter 3 is self.entity which in this case refers to the specific goblin model that the script is attached to.

 

Now the function "EnemyForEachEntityInAABBDoCallback(entity,extra)"

extra is the extra passed in from earlier (the goblin model) and entity an entity that that is within the aabb.

 

if extra.goblinai.target==nil then

extra is the passed parameter, which was self.entity (the goblin model), goblinai is the specific script attached to the goblin model and target is the variable (which was sloppily created on the fly, my bad).

 

 if extra~=entity then

You are trying to only find entites with a player script attached. So you begin by making sure that the entity in this call is not the goblin who the aabb is around.

 

  if entity.player~=nil then
   extra.goblinai.target=entity.player
  end

 

finally if the entity found is not the goblin and has a player script attached (entity.player~= nil) then the goblin's target is the new entity that is found.

 

 

extra.goblinai.target=entity.player

 

would not work because the entity that is passed in is not guaranteed to have a player script attached.

 

Wow this was a long winded answer, hopefully it helps a little. I can gladly explain / clarify any specific sections of code.

Share this post


Link to post

A couple of Android queries:

 

1) Will it be possible to change the build target from the default to 4.x.x Jellybean for instance?

 

2) Will it be possible to incorporate the Google licensing api if required?

 

3) If needs be am I free to modify the android manifest?

 

Thanks.

 

I'm going to have to deffer these to Josh.

Share this post


Link to post

Thanks a lot Chris smile.png

 

The code is lot more clear , now to understand.

 

yes extra was confusing.

 

self.entity.world

world means the word where is the entity goblin ? the level map ?

Share this post


Link to post

Hi, just tried to import a .obj but it does not show up in the assets, it copies the file into the project ok?. Importing .fbx seems to work fine.

Share this post


Link to post

Hi, how to set up an object to only detect a collision? I have tried the "trigger" option which works fine until I save it as a prefab and then use the prefab which results in a physical collision...

Share this post


Link to post
Guest Red Ocktober

how does the LE3 editor handle lighting of imported LE2 .gmfs with multiple materials ?

 

they look ok when in textured mode, but turn grey when lit...

 

disregard... figured it out...

 

whoever said that the new editor made some things easy wasn't kidding... maybe too easy...

 

--Mike

Share this post


Link to post

Hi, how to set up an object to only detect a collision? I have tried the "trigger" option which works fine until I save it as a prefab and then use the prefab which results in a physical collision...

That doesn't sound like it's working right...

Share this post


Link to post

Hi

 

What is required from custom meshes to be able to use lightmap properly?

I have a second uv channel and texture3 points to lightmap.tex, but I can't do it.

 

lightmap.jpg

Share this post


Link to post

I tested even having one UV only, i thaught LE 3 would create a second UV but nope.

 

Lightmapping only works on BSP.

 

And if it worked on models, how would we do if we had normap map shader ? could lightmapping work with it ?

It's really complicated i think.

 

If you need shadows, you'll have to wait fro some next update , than not use BSP, but models with shaders and shadows, i thinks they will be the two main ways of LE 3 :

BSP + lightmaps

Models + shaders + shadows

Share this post


Link to post

How to the more simply possible :

 

It's for some shooting example basic tutorial on space ship that can shoot others :

- Create a model or an array of models at runtime by Lua programming

- make it non collision and invisible

- switch to collision and visible

- move it to a point (i think i knwo how to do)

- on collision : detect what entity is hit

- make the model invisible , non collision

- keep the model to reuse it (like position on y = -1000)

- and at least remove it from the scene and memory (like game finished and return to menu)

Share this post


Link to post

I have noather question :

I have that code in App.lua :

 

local camera = Camera:Create()

camera:SetRotation(35,0,0)

camera:Move(0,0,-30)

 

 

It is possible to access to that camera from another script file attached to a character ? like simpleAI.lua ?

 

the camera is already global, because nto declared with self.camera ? os i should be able to use it anywhere ?

 

My calera is created in App.lua

And this code on simpleAI.lua attached ot a character don't work :

 

 

self.entity:GoToPoint(20,0,-15,1.4,1);

camera:Move(self.entity:getPosition().x,0,-30)

Share this post


Link to post

Remove the "local" and the variable will be global, and can be accessed from anywhere:

camera = Camera:Create()

 

We always use local variables or table values to avoid any problems of scripts using the same variable names.

 

Hi

 

What is required from custom meshes to be able to use lightmap properly?

I have a second uv channel and texture3 points to lightmap.tex, but I can't do it.

 

lightmap.jpg

You'll need to generate the lightmap data in another program until terrain is officially supported. The engine uses dynamic lighting for models and lightmaps for brushes, like the Source Engine does. I would just rely on dynamic lighting for now, personally.

Share this post


Link to post

It's in the code that you must detect goblins and set a target or directly set the target to some point in the space.

Share this post


Link to post

Where in the 3rdPersonFollow script does it set it to goblin? And why would the target be goblin when it would be the barbarian?

 

Andy

Share this post


Link to post

I don't think this code is valid ?

It don't contain any camera declaration ?

IF you attach this script to your character it won't work caus it is script to attacha camera it seems.

And camera are not an object you can pick up in the scene, so you can't bind it it seems.

Perhaps i'm wrong ?

 

Why not coding your own camera until some good camera template appears ?

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...