Jump to content

Recommended Posts

Posted

Thanks aiaf ! I learnt some new things from there ! One of them: global variables are ordinary variables !

 

After taking those tutorials it says that I'm a Lua expert ! On the tutorials page found here: http://www.leadwerks.com/werkspace/page/tutorials/

but I still can't place decals in my game yet lol so I don't feel like an expert just yet

Posted

stuck on this part:

 

anyone know how to convert this to lua ? :

 

switch( footprintType )

 

case 1 :

uvOffset = Vec2( 0.5, 1.0 )

break

 

case 2 :

Lua doesn't have a switch statement but you could do it with an if statement.

if footprintType  == 1 then
 uvOffset = Vec2(0.5, 1.0)
elseif footprintType == 2 then
  --blah blah
end

  • Upvote 1
Posted

var corners : Vector3[] = new Vector3[ 4 ];

 

to Lua How ?

Vector3 is Vec3 in Lua but what about the square brackets and colon ?

 

I believe corners is declared as a array of 4 vec3 values.

I think you only need to do this in lua:

corners = { }

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Posted

I believe corners is declared as a array of 4 vec3 values.

I think you only need to do this in lua:

corners = { }

That would make an array but to make equivalent code, wouldn't you need to fill it with the 4 Vec3 elements? Like:

corners = {Vec3(), Vec3(), Vec3(), Vec3()}

  • Upvote 1
Posted

yes, but you don't really need to declare anything in a table like that.

just table.insert when needed I guess. (I don't know whats next in line in the js script :-) )

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Posted

Thanks !

but idk what to use but this is the first part of it:

 

public function AddFootprint( pos : Vector3, fwd : Vector3, rht : Vector3, footprintType : int )

{

// - Calculate the 4 corners -

 

// foot offset

var footOffset : float = footprintSpacing;

 

if ( isLeft )

{

footOffset = -footprintSpacing;

}

 

var corners : Vector3[] = new Vector3[ 4 ];

 

// corners = position + left/right offset + forward + right

corners[ 0 ] = pos + ( rht * footOffset ) + ( fwd * footprintSize.y * 0.5 ) + ( -rht * footprintSize.x * 0.5 ); // Upper Left

corners[ 1 ] = pos + ( rht * footOffset ) + ( fwd * footprintSize.y * 0.5 ) + ( rht * footprintSize.x * 0.5 ); // Upper Right

corners[ 2 ] = pos + ( rht * footOffset ) + ( -fwd * footprintSize.y * 0.5 ) + ( -rht * footprintSize.x * 0.5 ); // Lower Left

corners[ 3 ] = pos + ( rht * footOffset ) + ( -fwd * footprintSize.y * 0.5 ) + ( rht * footprintSize.x * 0.5 ); // Lower Right

 

That function idk how to write that for lua. It has me so stumped and i cant find any lua script that looks like that to see how to make it

Posted

Thanks !

but idk what to use but this is the first part of it:

 

public function AddFootprint( pos : Vector3, fwd : Vector3, rht : Vector3, footprintType : int )

{

// - Calculate the 4 corners -

 

// foot offset

var footOffset : float = footprintSpacing;

 

if ( isLeft )

{

footOffset = -footprintSpacing;

}

 

var corners : Vector3[] = new Vector3[ 4 ];

 

// corners = position + left/right offset + forward + right

corners[ 0 ] = pos + ( rht * footOffset ) + ( fwd * footprintSize.y * 0.5 ) + ( -rht * footprintSize.x * 0.5 ); // Upper Left

corners[ 1 ] = pos + ( rht * footOffset ) + ( fwd * footprintSize.y * 0.5 ) + ( rht * footprintSize.x * 0.5 ); // Upper Right

corners[ 2 ] = pos + ( rht * footOffset ) + ( -fwd * footprintSize.y * 0.5 ) + ( -rht * footprintSize.x * 0.5 ); // Lower Left

corners[ 3 ] = pos + ( rht * footOffset ) + ( -fwd * footprintSize.y * 0.5 ) + ( rht * footprintSize.x * 0.5 ); // Lower Right

 

That function idk how to write that for lua. It has me so stumped and i cant find any lua script that looks like that to see how to make it

I think shadmar's line of code would fit better for this function than mine.

 

What part exactly has you stumped?

Posted

Like i said b4 the function part. This line:

 

public function AddFootprint( pos : Vector3, fwd : Vector3, rht : Vector3, footprintType : int )

You may want to look up some basic lua examples. This site seems decent

 

http://www.tutorialspoint.com/lua/lua_functions.htm

 

Regardless, this is how you make a similar function in lua:

function AddFootprint( pos, fwd, rht, footprintType)
 --blah blah
end

Posted

Thanks !

but i tried that and the other line that changes to corners = { } or the other way

corners = {Vec3(), Vec3(), Vec3(), Vec3()}

 

and then it gives an error at the start of this near = :

 

--// corners = position + left/right offset + forward + right

corners[ 0 ] = pos + ( rht * footOffset ) + ( fwd * footprintSize.y * 0.5 ) + ( -rht * footprintSize.x * 0.5 ); // Upper Left

corners[ 1 ] = pos + ( rht * footOffset ) + ( fwd * footprintSize.y * 0.5 ) + ( rht * footprintSize.x * 0.5 ); // Upper Right

corners[ 2 ] = pos + ( rht * footOffset ) + ( -fwd * footprintSize.y * 0.5 ) + ( -rht * footprintSize.x * 0.5 ); // Lower Left

corners[ 3 ] = pos + ( rht * footOffset ) + ( -fwd * footprintSize.y * 0.5 ) + ( rht * footprintSize.x * 0.5 ); // Lower Right

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.

×
×
  • Create New...