Author Topic: Help with Type  (Read 7456 times)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: Help with Type
« Reply #15 on: 2013-Feb-26 »
Quote
   FOREACH 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

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #16 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:

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #17 on: 2013-Feb-26 »
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 )

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: Help with Type
« Reply #18 on: 2013-Feb-26 »
I'm not sure, but I think yes whit short array can do complex things whit arrays, but I never uses...

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #19 on: 2013-Feb-26 »
Yes, you're right, I solved!  :good:

Offline siatek

  • Mr. Drawsprite
  • **
  • Posts: 59
    • View Profile
Re: Help with Type
« Reply #20 on: 2013-Feb-26 »
hmmmmmm

i think that mentalthink solved it ;)

glbasic roxx !!!

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #21 on: 2013-Feb-27 »
you think wrong  ;)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: Help with Type
« Reply #22 on: 2013-Feb-27 »
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:

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #23 on: 2013-Feb-27 »
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:

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #24 on: 2013-Mar-01 »
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


Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Help with Type
« Reply #25 on: 2013-Mar-01 »
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
« Last Edit: 2013-Mar-01 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Help with Type
« Reply #26 on: 2013-Mar-01 »
Many thanks Slydog  :good: