Help with Type

Previous topic - Next topic

mentalthink

QuoteFOREACH t IN Enemy[]
      FOREACH s IN Enemy[]
         IF Enemy[t].Y > Enemy.Y

You are wrong you have to write this...
FOREACH t IN Enemy[]
      FOREACH s IN Enemy[]
         IF t.Y > s.Y [/quote]

//I'm not sure if you can use 2 foreach one into the another, I suppose yes you can use, But I never use ... Try only whit a Bucle...

Remenber when you do foreach item in Enemy[]

You don't have to call enemy[].x <<< you don't have index here!!! the mode it's

foreach item in Enemy[]
   item.x    or anything you have declared in the Type ---- Endtype
<...>
next

Kyo

I have to rearrange a list of items from the lowest number to the highest.

And if I want to know the index of the array?

:booze:

Kyo

another problem   :-[:P
I have an array with these values:
arr [0 ] = 3
arr [1 ] = 6
arr [2 ] = 4
arr [3 ] = 1
arr [4 ] = 7

and I want to print in ascending order the list of numbers without touching the order of array (so I can use the command: SORTARRAY )

mentalthink

I'm not sure, but I think yes whit short array can do complex things whit arrays, but I never uses...

Kyo

Yes, you're right, I solved!  :good:

siatek

hmmmmmm

i think that mentalthink solved it ;)

glbasic roxx !!!

Kyo

you think wrong  ;)

matchy

Quote from: diego on 2013-Feb-26
I have to rearrange a list of items from the lowest number to the highest.

And if I want to know the index of the array?

:booze:

I haven't tried it for sometime so I'm not sure if it's right O_O but set the first TYPE item as id and it will be sorted by the one command SORTARRAY, eg.:
Code (glbasic) Select

TYPE TFoo
   id% // first item will be used as sorting index for whole type array with SORTARRAY
   x%
   y%
   name$
   // ...
ENDTYPE

:whistle:

Kyo

I know, but unfortunately SORTARRAY also reorder the index of the array, and I want to keep the same order, I solved with a simple bubble sort.  :good:

Kyo

How can I pass a Type in a function:

Code (glbasic) Select

TYPE tFX
id
        X
        Y
ENDTYPE

GLOBAL FX[] AS tFX
DIM FX[5]


FOREACH ent IN FX[]
Update_FX()
NEXT

FUNCTION Update_FX_ent:

ENDFUNCTION


Slydog

#25
A function that accepts a TYPE: (Using your example code)
Code (glbasic) Select
FUNCTION Update_FX: typeInstance AS tFX
typeInstance.id = 123
typeInstance.X = 1
typeInstance.Y = 2
ENDFUNCTION


To return a TYPE use this:
Code (glbasic) Select
FUNCTION Update_FX_ent AS tFX:
LOCAL returnType AS tFX
RETURN returnType
ENDFUNCTION


Then to call a function passing a TYPE instance:
Code (glbasic) Select
FOREACH ent IN FX[]
Update_FX(ent)
NEXT
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kyo

Many thanks Slydog  :good: