[Monkey] Merkwürdiger Fehler bei Maps
Übersicht

![]() |
The SharkBetreff: Merkwürdiger Fehler bei Maps |
![]() Antworten mit Zitat ![]() |
---|---|---|
Folgender Code gibt "Ergebnis2" aus. Eigentlich sollte "Ergebnis1" rauskommen. Ich habe keine Ahnung wieso das nicht passt. Vielleicht mach ich einen dummen Anfängerfehler, ist mein erster Tag mit Monkey ![]() Code: [AUSKLAPPEN] Class strEntry
Field entry:String End Class strMap Private Field sMap:StringMap<strEntry> Field tempEntry:strEntry Public Method New() Self.sMap = New StringMap<strEntry> Self.tempEntry = New strEntry End Method Set(Key:String,Value:String) tempEntry.entry=Value sMap.Set(Key,tempEntry) End Method Get:String(Key:String) Return sMap.Get(Key).entry End End Function Main() Local testmap:strMap= New strMap testmap.Set("Test1","Ergebnis1") testmap.Set("Test2","Ergebnis2") Print testmap.Get("Test1") End EDIT: Getter gekürzt |
||
![]() |
Suco-XBetreff: ....... |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi
du erstellst tmpEntry nur einmal und benutzt es für 2 Einträge die unterschiedliche Eigenschaften haben sollen. Das kann ja nicht funktionieren. Abgesehen davon schaut das ganze unnötig kompliziert aus. Wieso machst du nicht sowas wie hier: Code: [AUSKLAPPEN] Function Main() Local m:StringMap<StringObject> = New StringMap<StringObject> m.Set("Test1", "Ergebnis1") m.Set("Test2", "Ergebnis2") Print m.Get("Test1") End Mfg Suco |
||
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB |
![]() |
The Shark |
![]() Antworten mit Zitat ![]() |
---|---|---|
Danke für die Hilfe, jetzt gehts. StringObject kannte ich nicht. Ist das einfach eine Klasse, die Strings speichert?
Die Kostruktion hab ich gebaut, weil ich in einem Tutorial folgendes gelesen hatte:Zitat: Map – Map is used to link one object to another. Like this, Local map:= new Map<Car,Ship>. Car is the Key and Ship is the Value. You can’t use int,float,string with Map but there are special Maps for those cases, like this, Local map:= new StringMap<Car> this will create a Map with string as the Key, and Car as the Value.
|
||
![]() |
Suco-XBetreff: ...... |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi.
Du kannst dir die Klasse StringObject in module/monkey/boxes.monkey anschauen. Das gleiche gibt es auch für Ínteger und Float. Mfg Suco |
||
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group