two questions

Blitz3D Forums/Blitz3D Beginners Area/two questions

Alberto(Posted 2004) [#1]
hello

a couple of questions.

a) I tried to create an array of entity pointers, such as
n = 10
dim cube(n)
for i = 0 to i = n step 1

cube(i) = createCube()

next
but it does not work, why?

b) I created a mesh

man = LoadAnimMesh(" ..")


then I tried to use this entity as parent entity, something like
ball = createSphere(man)

but I get the error message " duplicate variable" referring to the entity man
Thanks in advance for your help


jhocking(Posted 2004) [#2]
a) Please be more specific than "it does not work." Do you get some error message? Are cubes created and you simply can't access them using the array?

From your code I'm guessing there is an out-of-bounds error because you are looping to n and not n-1.

b) The first parameter for CreateSphere is the number of segments; the parent is the second parameter. Thus the variable "man" is being interpreted incorrectly by the command (although I don't understand why it gives you a duplicate variable error specifically.) Change the line to something like:
ball = CreateSphere(8,man)


big10p(Posted 2004) [#3]

a) I tried to create an array of entity pointers, such as
n = 10
dim cube(n)
for i = 0 to i = n step 1

cube(i) = createCube()

next
but it does not work, why?



You syntax is wrong. Try:

n = 10 
dim cube(n-1) 
for i = 0 to n-1 
  cube(i) = createCube() 
next 



b) I created a mesh

man = LoadAnimMesh(" ..")


then I tried to use this entity as parent entity, something like
ball = createSphere(man)

but I get the error message " duplicate variable" referring to the entity man



Probably because the first argument of CreateSphere is the amount of segments you want, not the parent argument. Try:

ball = CreateSphere(8,man)


[edit] Ah, too slow. :P


jhocking(Posted 2004) [#4]
Dude, it took you 6 minutes to write that?

Are you sure he wants Dim cube(n-1)? I always forget, but while he wants n-1 in the loop, I think he would dim the array with n.


Warren(Posted 2004) [#5]
Yeah, dim the array with n but loop to n-1 ...


Alberto(Posted 2004) [#6]
thanks all for your reply

a) as far as I know in blitz basic an array cube(10) has 11 elements : cube(0),cube(1).....cube(10)
why should I loop 0 - 9 rather then 0 - 10?
however I did not get any error message as far as the for..next loop is concerned.
But when I call the comand, for example :
positionEntity cube(4),..,..,..,
I get the message "entity does not exist"

b)sorry I make a mistake in my post
please read : createCube(man) and not createSphere(man)
in this case there is one only option snd it should be the parent entity

Probably I did not mention a key information

I am using several "...bb" files
obviously I call the include "...bb" comand


jhocking(Posted 2004) [#7]
"as far as I know in blitz basic an array cube(10) has 11 elements : cube(0),cube(1).....cube(10)"

That is incorrect. The number you put in when dimming an array is the number of elements. Thus dim cube(10) will create an array with 10 elements, from cube(0) to cube(9)

Why you get the specific behavior you describe is a mystery to me. Try correcting your loop; maybe that won't fix your problem, but hey, it's worth a shot. By the way, you didn't answer my question. Are cubes actually being created? That is, do you see the cubes you created when rendering a camera view of the scene? If something goes wrong and prevents an entity from being created, you don't get any error until you attempt to use that entity in a command.

As for your other problem, you need to be more specific about your code. Explaining that you are using include files is a step in the right direction but not enough. For example, are the two lines you posted in different bb files?

I suspect the problem is due to sloppiness with the scope of the variable. Try declaring Global man at the top of your code, outside of any functions, and see if that helps.


overmeeren(Posted 2004) [#8]
"That is incorrect. The number you put in when dimming an array is the number of elements."

No that is incorrect :)

the number after dim is the index number of the last element not the number of elements

so dim(10) has in fact 11 elements


jhocking(Posted 2004) [#9]
Really? That's not what I've ever done, and that's not what it says here:
http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=gameac08292001.html

Then again, if what you say is true my mistaken way of using arrays would still work because I would always have an extra array element (as opposed to too few array elements, resulting in an out-of-bounds error.)


WolRon(Posted 2004) [#10]
Really? That's not what I've ever done, and that's not what it says here:
I would trust more what it says here:
http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Dim&ref=2d_cat


Zethrax(Posted 2004) [#11]
Regarding problem (b), if you're using the 'man' variable in your main code it will automatically be declared as a Global, so if you're also declaring 'Global man' elsewere then you will get a duplicate variable error.


jhocking(Posted 2004) [#12]
Well I'll be damned. All this time and I've been using arrays wrong.


eBusiness(Posted 2004) [#13]
a) As said, just write "n" instead of "i = n", the reason that you do not recieve an error is that the syntax is actually legimate, you can use "=" wherever you can use "+" or something similar, the result will be 1 if the statement is true and 0 if the statement is false, so in your code "i = n" will just equal to 0. Here is an example that demonstrate it:
a=6
b=6
Print a=b
WaitKey()



AbbaRue(Posted 2004) [#14]
I have never seen a line like this before.
for i = 0 to i = n step 1
I would rewrite that line as follows.
for i = 0 to n
that should work fine.


Alberto(Posted 2004) [#15]
thanks all

yes, it depends on the bloody "i = n "rather then a simple " to n "which I wrote this time , I do not know why