Liste in Mapelement ?!

Für allgemeine Fragen zur Programmierung mit PureBasic.
True29
Beiträge: 283
Registriert: 18.08.2012 19:18
Computerausstattung: Windows 8 64bit .Profan x2,Purebasic 5.5
Wohnort: Worms
Kontaktdaten:

Liste in Mapelement ?!

Beitrag von True29 »

funktioniert wohl nicht ? oder habe ich einen fehler gemacht ?

zeile : gameb()\PositionID = *gamebuttons\buttons()\PositionID

ziel des codes ist es , den listeninhalt vom map element , in einer neuen liste zu haben.

danke für hinweise :(
hm vielleicht hätte ich einfach CopyList benutzen können ?
CopyList(gamebuttons("Gravity")\buttons(),gameb())
gerade getestet klappt auch nicht.

grüße.



lauffähiger democode.

Code: Alles auswählen

EnableExplicit

Structure vector2d
  x.f
  y.f
EndStructure


;// buttons
Structure bt
  PositionID.i ;// position ID top , down , play
  text.s
  Image.i
  Position.vector2d
  size.f
  intensity.f  
  color.i  
  path.s
  filename.s
EndStructure

Structure test
  List buttons.bt()  
EndStructure

Global NewMap gamebuttons.test()
Global NewList gameb.test()

Procedure convertmaptolist(*gamebuttons.test)
  ForEach *gamebuttons\buttons()
    AddElement(gameb())      
        gameb()\PositionID = *gamebuttons\buttons()\PositionID
        gameb()\Image = *gamebuttons\buttons()\Image
        gameb()\color = *gamebuttons\buttons()\color
        gameb()\intensity = *gamebuttons\buttons()\intensity
        gameb()\filename = *gamebuttons\buttons()\filename
        gameb()\path = *gamebuttons\buttons()\path
        gameb()\Position\x = *gamebuttons\buttons()\Position\x
        gameb()\Position\y = *gamebuttons\buttons()\Position\y
        gameb()\size = *gamebuttons\buttons()\size
   Next
 EndProcedure
 
;// add to buttons to map 
  AddElement(gamebuttons("Gravity")\buttons())
  With gamebuttons("Gravity")\buttons()
    ;// bg image
        \PositionID = 0
        \Image = 1
        \color = #PB_Ignore
        \intensity = 255
        \filename = "bg.jpg"
        \path = ""
        \Position\x = 0
        \Position\y = 0
        \size = #PB_Ignore
  EndWith
      
      
  AddElement(gamebuttons("Gravity")\buttons())
  With gamebuttons("Gravity")\buttons()
    ;// bg image
        \PositionID = 1
        \Image = 2
        \color = #PB_Ignore
        \intensity = 255
        \filename = "bg.jpg"
        \path = ""
        \Position\x = 0
        \Position\y = 0
        \size = #PB_Ignore
  EndWith
  
  ;// map
  ForEach gamebuttons("Gravity")\buttons()
    Debug gamebuttons("Gravity")\buttons()\PositionID
    Debug gamebuttons("Gravity")\buttons()\filename
  Next
  
  
  convertmaptolist(gamebuttons("Gravity"))
  
  ;// list
  ForEach gamebuttons("Gravity")\buttons()    
    Debug gameb()\buttons()\PositionID
    Debug gameb()\buttons()\filename    
  Next

i7,12gb ram , Windows 10 ,Purebasic 5.50
Benutzeravatar
man-in-black
Beiträge: 362
Registriert: 21.08.2006 17:39

Re: Liste in Mapelement ?!

Beitrag von man-in-black »

Du hast dich mit deinen ganzen Listen zu sehr verschachtelt. Die Map ist i.O., aber deine parallel geführte Liste nicht.

Habe einfach ein AddElement vor die Procedure gezogen und den Inhalt der Procedure etwas modifiziert:

Code: Alles auswählen

EnableExplicit

Structure vector2d
  x.f
  y.f
EndStructure


;// buttons
Structure bt
  PositionID.i ;// position ID top , down , play
  text.s
  Image.i
  Position.vector2d
  size.f
  intensity.f 
  color.i 
  path.s
  filename.s
EndStructure

Structure test
  List buttons.bt() 
EndStructure

Global NewMap gamebuttons.test()
Global NewList gameb.test()

AddElement(gameb())

Procedure convertmaptolist(*gamebuttons.test)
  ForEach *gamebuttons\buttons()
    AddElement(gameb()\buttons())     
        gameb()\buttons()\PositionID = *gamebuttons\buttons()\PositionID
        gameb()\buttons()\Image = *gamebuttons\buttons()\Image
        gameb()\buttons()\color = *gamebuttons\buttons()\color
        gameb()\buttons()\intensity = *gamebuttons\buttons()\intensity
        gameb()\buttons()\filename = *gamebuttons\buttons()\filename
        gameb()\buttons()\path = *gamebuttons\buttons()\path
        gameb()\buttons()\Position\x = *gamebuttons\buttons()\Position\x
        gameb()\buttons()\Position\y = *gamebuttons\buttons()\Position\y
        gameb()\buttons()\size = *gamebuttons\buttons()\size
   Next
 EndProcedure
 
;// add to buttons to map
  AddElement(gamebuttons("Gravity")\buttons())
  With gamebuttons("Gravity")\buttons()
    ;// bg image
        \PositionID = 0
        \Image = 1
        \color = #PB_Ignore
        \intensity = 255
        \filename = "bg.jpg"
        \path = ""
        \Position\x = 0
        \Position\y = 0
        \size = #PB_Ignore
  EndWith
     
     
  AddElement(gamebuttons("Gravity")\buttons())
  With gamebuttons("Gravity")\buttons()
    ;// bg image
        \PositionID = 1
        \Image = 2
        \color = #PB_Ignore
        \intensity = 255
        \filename = "bg.jpg"
        \path = ""
        \Position\x = 0
        \Position\y = 0
        \size = #PB_Ignore
  EndWith
 
  ;// map
  ForEach gamebuttons("Gravity")\buttons()
    Debug gamebuttons("Gravity")\buttons()\PositionID
    Debug gamebuttons("Gravity")\buttons()\filename
  Next
 
 
  convertmaptolist(gamebuttons("Gravity"))
 
  ;// list
  ForEach gamebuttons("Gravity")\buttons()   
    Debug gameb()\buttons()\PositionID
    Debug gameb()\buttons()\filename   
  Next
MFG
MIB
(hab alles, kann alles, weiß alles!!^^)

Bild
True29
Beiträge: 283
Registriert: 18.08.2012 19:18
Computerausstattung: Windows 8 64bit .Profan x2,Purebasic 5.5
Wohnort: Worms
Kontaktdaten:

Re: Liste in Mapelement ?!

Beitrag von True29 »

danke ;) ja jetzt sehe ich auch wo der denkfehler war :(
i7,12gb ram , Windows 10 ,Purebasic 5.50
Antworten