1
myMesh = {}
myMesh[0].x = 30

Nope... doesn't work.

myMesh = Mesh.new{}
myMesh[0].x = 30

Nope... no go.

An array of meshes should be possible, but I don't know how. Can someone help? Thanks

Edit: Thanks for your responses. Pardon me for this stupid mistake. I just realized, "What nonsense are you doing J?" I really wanted an array of vertices of the mesh, so that I can use loops to manipulate them. Sorry about that... although it didn't hurt to learn how to get an array of meshes.

So I figured it out, because I was sure I did this before, when I used gml.

ptx = {}; pty = {}; ptz = {} 
ptx[1] = myMesh.x; pty[1] = myMesh.y; ptz[1] = myMesh.z; 

Thanks for the help though. I also learned that lua doesn't use index 0

Edit: Wait. That doesn't work either does it?

Well for now this gives no error, so I'll see if it does what I want.

pMesh = {}
 for m=1, 6 do
    pMesh[m] = Mesh.new()
 end

pMesh[1].x = 0; pMesh[1].y = 0; pMesh[1].z = 0

Thanks guys. If you have any other suggestions, I'm all ears.

Jillinger
  • 172
  • 2
  • 11
  • besides the Lua syntax errors, this doesn't make sense. why would a mesh have an x coordinate? what do you want to achieve? – Piglet Apr 10 '18 at 14:40

3 Answers3

1
myMesh = {}
myMesh[0].x = 30

Will cause an error for indexing a nil value.

myMesh = {} creates an empty Lua table.

doing myMesh[0].x is not allowed because there is no myMesh[0]. First you have to insert a table element at index 0.

myMesh = {}
myMesh[0] = Mesh.new(true)
myMesh[0].x = 30

myMesh is a stupid name for an array of meshes as it suggests it's just a single mesh. Also in Lua we usually start with index 1 which will makes things a bit easier using Lua's standard table tools. I'm not sure if

mesh = Mesh.new()
mesh.x = 30

is actually ok. Why would a mesh have an x coordinate? This is not listed in Mesh's properties in the manual.

Usually you would create a Mesh with multiple points And if you want an array of multiple meshes you would simply put those meshes into a table unless there is a particular user data type for this.

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • Just wanted to let you know guys know - using an array of meshes to store the vertex position worked perfectly. Thanks a lot. – Jillinger Apr 11 '18 at 00:58
0

Try this:

myMesh = {}
myMesh[0]= Mesh.new{}
myMesh[0].x = 30
lhf
  • 70,581
  • 9
  • 108
  • 149
0

you need to initialize as a table and columns and rows:

myMesh = {}
myMesh[0] = {}
myMesh[0].x=30

or

myMesh = { [0]={} }
myMesh[0].x=30
Mike V.
  • 2,077
  • 8
  • 19