DELPHI zmienia typ zmiennej z Byte na Extended

0
 
program Swiat_Velderu1x18;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

var // zmienne uzyte w tym fragmencie
  rand : Integer;
  hp, ehp : Integer;
  hpprocent, ehpprocent : Integer;
  dmg, edmg, factdmg, efactdmg, sdeath, edeath, death, walka : byte;
  miksturahp, emiksturahp, zbroja, ezbroja : byte;
  name : String;
  
/// UWAGA! Fragment(calość ma 2k linijek)
begin // ogolny poczatek

While sdeath < 1 do 
   begin // petla dopoki ktorys z walczacych nie umrze
   name := 'entrick';
   hp := 120;
   dmg := 17;
   miksturahp := 5;
   zbroja := 1;
   ehp := 30;
   edmg := 17;
   ezbroja := 0;
   emiksturahp := 2;

   Writeln('_______________________________________________________________________________');
   Writeln('__________________________________WALKA!______________________________________');
   Writeln('_____',name,'_________________________vs________________________Przeciwnik_______');
   Writeln('_____________________________________|_________________________________________');
   Writeln('_____________________________________|_________________________________________');
   Writeln('_____MIKSTURY:__________',miksturahp,'____________|_______________',emiksturahp,'_________________________');
   Writeln('_____HP:________________',hp,'___________|_______________',ehp,'________________________');
   Writeln('_____DMG(+/- 10): ______',dmg,'___________|_______________',edmg,'________________________');
   Writeln('_____ZBROJA:____________',zbroja,'____________|_______________',ezbroja,'_________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_____1 - użyj mikstury,________________________________________________________');
   Writeln('_____2 - obrona,_______________________________________________________________');
   Writeln('_____3 - atak__________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('______________Aby kontynuowac wybierz i wcisnij klawisz [ENTER]________________');
   Writeln('_______________________________________________________________________________');
   Readln(walka); // ^^^ w konsoli wyglada to jak pelny ekran :D
   Randomize;                    // poczatek obrazenia +/- 10
   rand := RandomRange(-10, 10);
   factdmg := dmg-rand;
   efactdmg := edmg-rand;        // koniec obrazenia +/- 10

// Ogolnie - Mikstura normalne dmg dla obu stron, gracz +25hp
// Ogolnie - Obrona   dmg-5 dla obu stron
// Ogolnie - Atak dmg+10 dla obu stron
// Ogolnie - reszta w if-ach zbroja 1 = -20% do dmg, zbroja 2 = - 35% do dmg.

   If walka = 1 then
      begin // poczatek uzyj mikstury
      If miksturahp < 1 then
         begin
         Writeln('Nie masz mikstur!');// ERROR NIE MASZ MIKSTUR
         end;
      If miksturahp > 0 then
         begin
         If zbroja = 0 then
            begin
            hp := hp-efactdmg+25;
            end;
         If zbroja = 1 then
            begin
            hpprocent := efactdmg*0.2;          //obrazenia := obrazenia - 20% LINIJKA nr. 2143(pierwszy error)
            hp := hp-efactdmg+hpprocent+25; //nie wiem czemu delphi mimo zadeklarowania efactdmg jako byte  
            end;                                         // uznaje efactdmg jako extended. Prosze o pomoc
         If zbroja = 2 then
            begin;
            hpprocent := efactdmg*0.35;    //obrazenia := obrazenia - 35%
            hp := hp-efactdmg+hpprocent+25;
            end;

         If ezbroja = 0 then
            begin
            ehp := ehp-factdmg;
            end;
         If ezbroja = 1 then
            begin
            ehpprocent := factdmg*0.2;
            ehp := ehp-factdmg+ehpprocent;
            end;
         If ezbroja = 2 then
            begin;
            ehpprocent := factdmg*0.35;
            ehp := ehp-factdmg+ehpprocent;
            end;
         miksturahp := miksturahp-1;
         end;  // koniec jesli miksturahp > 0
      end;  // koniec uzyj mikstury
   If walka = 2 then
      begin // poczatek obrona
      If zbroja = 0 then
         begin
         hp := hp-efactdmg+5;
         end;
      If zbroja = 1 then
         begin
         hpprocent := efactdmg*0.2;
         hp := hp-efactdmg+hpprocent+5;
         end;
      If zbroja = 2 then
         begin;
         hpprocent := efactdmg*0.35;
         hp := hp-efactdmg+hpprocent+5;
         end;

      If ezbroja = 0 then
         begin
         ehp := ehp-factdmg+5;
         end;
      If ezbroja = 1 then
         begin
         ehpprocent := factdmg*0.2;
         ehp := ehp-factdmg+ehpprocent+5;
         end;
      If ezbroja = 2 then
         begin;
         ehpprocent := factdmg*0.35;
         ehp := ehp-factdmg+ehpprocent+5;
         end;
       end;  // koniec obrona
    If walka <> 1 then // nie przyjmuje mi warunku zlozonego - tak dla wyjasnienia
       begin // poczatek walka <> 1
       If walka <> 2 then
          begin // poczatek walka <> 1 i 2
             If walka = 3 then
                begin // poczatek atak
                If zbroja = 0 then
                   begin
                   hp := hp-efactdmg-10;
                   end;
                If zbroja = 1 then
                   begin
                   hpprocent := efactdmg*0.2;
                   hp := hp-efactdmg+hpprocent-10;
                   end;
                If zbroja = 2 then
                   begin;
                   hpprocent := efactdmg*0.35;
                   hp := hp-efactdmg+hpprocent-10;
                   end;

                If ezbroja = 0 then
                   begin
                   ehp := ehp-factdmg-10;
                   end;
                If ezbroja = 1 then
                   begin
                   ehpprocent := factdmg*0.2;
                   ehp := ehp-factdmg+ehpprocent-10;
                   end;
                If ezbroja = 2 then
                   begin;
                   ehpprocent := factdmg*0.35;
                   ehp := ehp-factdmg+ehpprocent-10;
                   end;
                   end   // koniec atak
          else // jesli walka <> 1,2 i 3
             begin // poczatek error wyboru
             Writeln('ERROR!');
             end;  // koniec error wyboru
          end;  // koniec walka <> 1 i 2
       end;  // koniec walka <> 1

   Writeln('_______________________________________________________________________________');
   Writeln('__________________________________WALKA!_______________________________________');
   Writeln('_____',name,'_________________________vs________________________Przeciwnik_______');
   Writeln('_____________________________________|_________________________________________');
   Writeln('_____________________________________|_________________________________________');
   Writeln('_____MIKSTURY:__________',miksturahp,'____________|_______________',emiksturahp,'_________________________');
   Writeln('_____HP:________________',hp,'___________|_______________',ehp,'________________________');
   Writeln('_____DMG(+/- 10): ______',dmg,'___________|_______________',edmg,'________________________');
   Writeln('_____ZBROJA:____________',zbroja,'____________|_______________',ezbroja,'_________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('___123456_zadaje obrażenia za: __',factdmg,'__|_Przeciwnik:__',efactdmg,'________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('_______________________________________________________________________________');
   Writeln('______________________Aby kontynuowac wcisnij klawisz [ENTER]__________________');
   Writeln('_______________________________________________________________________________');
   Readln;
   If ehp < 21 then
      begin 
      If emiksturahp > 0 then
      Writeln('Przeciwnik uzywa mikstury!');
      emiksturahp := emiksturahp-1;
      ehp := ehp + 25;
      end;
   If ehp < 1 then edeath := 1;
   If hp < 1 then death := 0;
   sdeath := death+edeath;
end;  // koniec petla dopoki ktorys z walczacych nie umrze
end. // ogolny koniec

Błędy:

[Error] Swiat_Velderu1x18.dpr(2143): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2148): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2158): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2163): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2177): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2182): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2192): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2197): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2213): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2218): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2228): Incompatible types: 'Integer' and 'Extended'
[Error] Swiat_Velderu1x18.dpr(2233): Incompatible types: 'Integer' and 'Extended'

obrazenia := obrazenia - 20%
LINIJKA nr. 2143(pierwszy error) - Nie wiem czemu delphi, mimo zadeklarowania efactdmg jako byte, uznaje efactdmg jako extended. Bardzo proszę o pomoc.

1
var
  hpprocent: Integer;
  efactdmg: Byte;

hpprocent := efactdmg*0.2;

Mnożysz zmienną całkowitą typu Byte przez ułamek i chcesz wynik podstawić pod zmienną całkowitą (typu Integer).
Skąd pewność, że wynik również będzie liczbą całkowitą?. Nie wiesz tego, kompilator też nie wie i dlatego zgłasza błąd. Oczywiście w takim przypadku zmienna hpprocent musi być typu rzeczywistego

0
simplex napisał(a)
var
  hpprocent: Integer;
  efactdmg: Byte;

hpprocent := efactdmg*0.2;

Mnożysz zmienną całkowitą typu Byte przez ułamek i chcesz wynik podstawić pod zmienną całkowitą (typu Integer).
Skąd pewność, że wynik również będzie liczbą całkowitą?. Nie wiesz tego, kompilator też nie wie i dlatego zgłasza błąd. Oczywiście w takim przypadku zmienna hpprocent musi być typu rzeczywistego

Dzięki za pomoc

1 użytkowników online, w tym zalogowanych: 0, gości: 1