testing it out

Blitz3D Forums/Blitz3D Beginners Area/testing it out

seferey(Posted 2006) [#1]
I was using off of the forums here a code that can position a entity but where it says position entity it had more codes for texturing entity and scaling stuff like that


Dim box$(4)
For m = 1 To 4
box$(m)=LoadMesh("ring1.3ds")
box$(m1)=LoadMesh("ring2.3ds")
PositionEntity box$(m),Rand(30,30),0,Rand(-30,-30)
PositionEntity box$(m1),Rand(50,50),0,Rand(-50,-50)
Next



by the way this actually works the only I want to do now is duplicate the ring1 and ring2 entities to make more


jfk EO-11110(Posted 2006) [#2]
It seems you should try to understand the diffrences between strings and integers, as well as the way arrays work.

First, when using LoadMesh you should use an integer variable to hold the handle. If you don't (as you are using a string variable) you will not be able to keep control over the mesh. Although it may work noless due to Blitzbasics automatic type conversion, it's definitively not the way it's supposed to be (note: strings are those variables and arrays that are using the dollar sign)

Second, in your example you are using "m1" as the index when loading. This will always be zero (unlike "m" that is incremented by the "For" loop).

Here's an example based on your code that proofes what's wrong with it:

Dim box$(4)
For m = 1 To 4
 box$(m)=LoadMesh("ring1.3ds")
 box$(m1)=LoadMesh("ring2.3ds")
 PositionEntity box$(m),Rand(30,30),0,Rand(-30,-30)
 PositionEntity box$(m1),Rand(50,50),0,Rand(-50,-50)
Next
For m = 1 To 4
 entitycolor box$(m),255,0,0
 entitycolor box$(m1),0,255,0 ; we have lost control over the first 3 loaded ring2 meshes
Next

you see some of them wasn't colored. These are the ones we have lost control because m1 was always zero, the handle "box$(0)" was overwritten.

Here's the same in a more proper implementation:
Dim box(4,1)
For m = 1 To 4
 box(m,0)=LoadMesh("ring1.3ds")
 box(m,1)=LoadMesh("ring2.3ds")
 PositionEntity box(m,0),Rand(30,30),0,Rand(-30,-30)
 PositionEntity box(m,1),Rand(50,50),0,Rand(-50,-50)
Next
For m = 1 To 4
 entitycolor box(m,0),255,0,0
 entitycolor box(m,1),0,255,0 
Next

BTW. you may duplicate things by using the CopyEntity command.


seferey(Posted 2006) [#3]
when I copyentity it gives me

"Identifier box may not be used like this"

box3=CopyEntity(box)


mindstorms(Posted 2006) [#4]
box is already being used, as the handle to the array. Use another name for the original entity to be copied from.


jfk EO-11110(Posted 2006) [#5]
again, first find out what arrays are.

box3=CopyEntity( box(0,0) )

when you say

Dim box(100,100)

then you will have 100*100 box'es, from box(0,0) up to box(100,100), where both indexes may be any number between 0 and 100 (thus 100*100 possible variables in the array)

In fact its 101*101 because arrays start at index 0, not 1.

This kind of storage is very useful when you have data that corresponds with the array structure, like a chessboard that has 8*8 fields, so you could use an array with 8*8 fields as well and store every fields figure in the array:

dim chessboard (8,8)

Now when you have DIMed an array, you have to use the brackets and a valid index each time you are using it. Cause "box" isn't the same as "box(i,j)".