Jump to content

js to lua


awgsknite
 Share

Recommended Posts

I suggest you start with the lua tutorials from this site and after the Lua reference manual.

Here you go http://www.lua.org/docs.html

Take a few days for this or how long you need to be confident with your lua knowledge.

 

After doing this you should be able to convert this js by yourself if you still need it.

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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