Autor Beitrag
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mo 21.04.03 23:50 
Hallo,
ich schreibe gerade einen Level Editor für mein Neues Spiel, und dabei triet ein Fehler auf, beim abspeichern des Levels, der Fehler ist folgender:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Draw_Karte {
########################################  
#                                      #  
###################################### #  
#                                      #  
#                                      #  
#                                      #  
#                                      #  
#                                      #  
#                                      #  
#                                      #  
# ######################################  
#                                      #  
#                                      #  
###################################### #  
#  #                                  - #  
#  #  #                               - #  
#  #  #      -                          #  
#  #  #                                #  
#     #-                                #  
#     #                 -               #  
#     #-                                #  
# ##  ##################################  
#                                     - #  
########################################  
Draw_Karte }

diese Datei sollte aber so aussehen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Draw_Karte {
########################################
#                                      #
###################################### #
#                                      #
#                                      #
#                                      #
#                                      #
#                                      #
#                                      #
#                                      #
# ######################################
#                                      #
#                                      #
###################################### #
#  #                                  -#
#  #  #                               -#
#  #  #      -                         #
#  #  #                                #
#     #-                               #
#     #                 -              #
#     #-                               #
# ##  ##################################
#                                     -#
########################################
Draw_Karte }

also fürs Speichern nutze ich folgenden Code:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
procedure str_into_RichEdit(Liste1215:TStringList;Insert_Text:string; line:integer; position:integer);
var
  h : integer;
begin
  with Liste1215 do begin
    for h := Count to line-1 do Add('');
      for h := length(Strings[line-1]) to position do Strings[line-1] := Strings[line-1] + ' ';
      Strings[line-1] := copy(Strings[line-1], 1, position-1) + Insert_Text + copy(Strings[line-1], position, length(Strings[line-1]));
  end;
end;


procedure TSpiel.SaveGame(pFileName:String);
var
  x,y,i:Integer;
  Inhalt:TStringList;
begin
  Inhalt:=TStringList.Create;
  with Inhalt do begin
    add('Draw_Karte {');
    for y:=0 to MapY do begin
      for x:=0 to MapX do begin
        if Map[x,y].Typ = Wand then str_into_RichEdit(inhalt,'#',y+IndexOf('Draw_Karte {')+2,x+1);
      end;
    end;

// Hier tritt der Fehler auf, warum weiß ich nicht....
    for i:=0 to High(Platten) do begin
      with Platten[i] do begin
        if Typ = PlateX then begin
          if Speed = rx then begin
            str_into_RichEdit( inhalt,'-',y+IndexOf('Draw_Karte {')+2,x+1 )
          end;
        end;
      end;
    end;

    add('Draw_Karte }');
    SaveToFile(pFileName);
  end;
end;


Kann mir bitte jemmand sagen, wo der fehler im code liegt ?
ich finde in einfach nicht :oops:

_________________
MFG
Michael Springwald, "kann kein englisch...."
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Di 22.04.03 15:54 
keiner eine lösung ???
schade....

_________________
MFG
Michael Springwald, "kann kein englisch...."
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Di 22.04.03 17:20 
Nanana, nicht so ungeduldig, ich musste ihn dreimal gelesen, bevor ich den Fehler gefunden hab'.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
with Liste1215 do begin
  for h := Count to line-1 do
    Add('');

  for h := length(Strings[line-1]) to position do
    Strings[line-1] := Strings[line-1] + ' ';

  Strings[line-1] := copy(Strings[line-1], 1, position-1) + Insert_Text + copy(Strings[line-1], position, length(Strings[line-1]));

end;

Hier liegt der Fehler.
Wenn ich richtig gesehen habe, gehst du jede X-Position einzeln durch, schreibst also hintereinander. Die '-' werden dann nachher eingefügt, es muss also eine Lücke geschaffen werden und diese darauf wieder mit dem entsprechenden Zeichen gefüllt werden.
Ich hoffe, daß die Lösung so einfach ist, wenn nicht, habe ich den Code falsch verstanden:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
with Liste1215 do begin
  for h := Count to line-1 do
    Add('');

  for h := length(Strings[line-1]) to position do
    Strings[line-1] := Strings[line-1] + ' ';

  Strings[line-1] := copy(Strings[line-1], 1, position-1) + Insert_Text + copy(Strings[line-1], position+1, length(Strings[line-1]));

end;

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Di 22.04.03 18:04 
Danke, es funktionirt

_________________
MFG
Michael Springwald, "kann kein englisch...."