Float[]

Monkey Forums/Monkey Programming/Float[]

hardcoal(Posted 2011) [#1]
Local Dada:Float[]

How do I add to the Float List another Number

Lets Say Dada=[45.0,23.0]

Now I want to add another number to the list
how can I do that?

I want Dada to be Dada[45.0,23.0,45.2]

Cheers


Xaron(Posted 2011) [#2]
I would use a list or stack for dynamic arrays.


hardcoal(Posted 2011) [#3]
I dont know how to use Stack nor Dynamic Arrays


Xaron(Posted 2011) [#4]
I will give you an example later. Currently I'm not at home...


hardcoal(Posted 2011) [#5]
:) ok tanx
meanwhile... trail and error...


AdamRedwoods(Posted 2011) [#6]
...or...
Local dada:Float[] = [45.0, 23.0]
dada = dada.Resize( dada.Length()+1 )
dada[dada.Length()-1] = 45.2

For Local i:= 0 To dada.Length()-1
	Print dada[i]
Next


...or....
Local dada:FloatList = New FloatList ''or FloatStack
dada.AddLast(45.0) ''stack uses Push()
dada.AddLast(23.0)
''..etc..
dada.AddLast(45.2)

For Local i:= EachIn dada
        Print i
Next



hardcoal(Posted 2011) [#7]
Greate help thanks adam
thats all i need a simple code example saves 1000 tutorials.

but why does the floatlist doesnt work on polydraw?

I mean Example:

Local dada:FloatList
dada.AddLast(45.0)
dada.AddLast(23.0)
DrawPoly(dada)

gives an error "Unable to find overload for DrawPoly(FloatList)"


hardcoal(Posted 2011) [#8]
Im making an online Help for monkey so everything im learning will be added to the Guide.
The Guide will be In a CHM file Style.
And will be with code examples
and will cover Box2D, and anything that I will decide.
Also if some people would like to edit it in the future
I will give them access to improve its level.

Another quastion..

Example:
Function Test(Xpos=0,Dada:Float[]=0)

How can i make that the Dada in the function can be skiped like you do when you put 0 on XPos in case i dont want to enter Data


Goodlookinguy(Posted 2011) [#9]
You should look through the Monkey documentation for built-in functionality.

DrawPoly can't take a list, but it can take an array. If it's unable to find an overload for DrawPoly, that means it has no way to handle the input. So a quick look around the documentation would have found you the answer very quickly.
DrawPoly(dada.ToArray())


For the other example, I don't know if the documentation clearly states it, but it's surely implied. Here's the minor fix to give an array a default value.
Function Test( xPos = 0, data:Float[] = [] )



hardcoal(Posted 2011) [#10]
Tnx. Great Help!
Simple. and to the point.

Another interesting quastion I always wondred..

When you use a function can you tell the give the function a sign
that tells it to use the default value and skip to the next Entry.

Example:

Function Dada(Xpos=34,YPos=23)
code...
End Function

Dada([SkipXPos],45)

I will also look into the docs tnx


hardcoal(Posted 2011) [#11]
Im writing..

Class Element
field LFloat:Float[]
End Class

NewE:Element=New Element

NewE.LFloat.Resize(2)

Print NewE.LFloat.Length --> brings answer 0

any idea why


c.k.(Posted 2011) [#12]
hardcoal, is it going to be like a wiki? That would be most helpful, as long as it has good search functionality.


hardcoal(Posted 2011) [#13]
Im using a Help Maker software with its familiar options like

Content,Index,Search,Favorits

Always will be improved.. with some nice help of the community

Thats the plan for now


Xaron(Posted 2011) [#14]
Looks like your problem has been solved! :)


hardcoal(Posted 2011) [#15]
Not really Xaron

im working all day trying to make A drawpoly function.
yet no success.

look at this code

Import mojo

Global Tata:Float[]

Function Main()
New TestLoop
End Function


Class TestLoop Extends App

Method OnCreate()
SetUpdateRate(60)
Tata.Resize(3)
Print Tata.Length
End Method

Method OnRender()
Cls
End Method

End Class

Why when I Print I get Result Zero and not 3


GfK(Posted 2011) [#16]
Because your code is wrong.
Tata = Tata.Resize(3)



hardcoal(Posted 2011) [#17]
uhhm I was counting on that fact that my code was wrong.
other wise it would be working.

thanks for the solution