Glen Morse
Glen Morse

Reputation: 2593

Editing Hint Locks up program

I was wanting to show a Map(myclass) hint when a user rolls over an image on my map. If i do something simple like make hint say "Monster here" it works, But what I was going for was to show all the monster details in the hint. When I do this the hint never shows up and program locks up. Maybe its too much?

Procedure is onmousemove

procedure TBaseGameForm.HexMap1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
   position:TPoint;
   i : integer;
   totalplayers : integer;
   name : String;
   Life,movement,magical1,magical2,Attack1,Attack2,Crit,Def : String;
 begin
     position := hexmap1.convertcoords(point(x,y),ptXY);
     if FGamePlay.Locations.IndexOfName(inttostr(Position.x)+inttostr(Position.Y)) <> -1 then begin
        if FGamePlay.ShowHints = true then
          exit;
        FGamePlay.ShowHints := true;
        i:=1;
        while i <= FGamePlay.NumberOfHostPlayers do
            begin
              if (FMyPlayers.player[i].Values['posx'] = inttostr(Position.X)) AND (FMYPlayers.player[i].Values['posy'] = inttostr(Position.Y)) then
                 begin
                   With FMyPlayers.player[i] Do begin
                     name := values['name'];
                     life := values['life'];
                     movement := values['move'];
                     magical1 := values['magical1'];
                     Attack1 := 'Magical: '+Magical1+' '+Values['attack1']+'-p'+values['Power1']+'/r'+Values['Range1']+' '+Values['Ticks1']+' Ticks';
                     magical2 := values['magical2'];
                     Attack2 := 'Magical: '+Magical2+' '+Values['attack2']+'-p'+values['Power2']+'/r'+Values['Range2']+' '+Values['Ticks2']+' Ticks';
                     Crit := values['crit'];
                     Def := 'Magic def : '+values['defm']+' Normal def : '+values['defn'];
                   end;
                 end;
            end;
       hexmap1.ShowHint := true;
       hexmap1.Hint := 'Name: '+name+' Life: '+Life+' Move: '+Movement+ #13#10 +Attack1+ #13#10 +Attack2+ #13#10 +Def+ #13#10 +'Crit bonuse: '+crit;
     end
     else
       Hexmap1.ShowHint := false;
       FGamePlay.ShowHints := False;

 end;

Ill explain it the best i can and what i am trying to have it do. It starts by converting the x,y into a spot on my map(position). Then it checks a stringlist called locations for the location value, if it finds one its saying there is a monster at that location.

I Added this extra part to see if it helped, if i have fgameplay.showhints = true then no need to turn on hints or change var because the area on map is same, Once the area has changed(mouse moved away from monster) then fgameplay.showhints is false and now needs new data if found. (not sure this is needed but sounded good..)

so now it starts to look for the data to add to the hint. FMyPlayers.player[i] each one is a stringlist holding values for different items.

Hope i made this clear i tried the best i can. also For now its just the FMyPlayers but there will also be a FTherePlayers which will be another while loop checking i vs number of client players.

any questions or if something is not clear please ask. my goal is to figure out why it keeps freezing, maybe instead of onmousemove i should do something else? cheers squills

Upvotes: 1

Views: 110

Answers (1)

Dampsquid
Dampsquid

Reputation: 2474

Try adding an inc(i) inside your while loop, your not incrementing the value so its locked inside the while.

Or better still use a for loop since you already know the number of itterations.

Upvotes: 5

Related Questions