Variable "doesn't exits"

Maps and the art of mapmaking.
tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Variable "doesn't exits"

Unread postby tofiffe » 16 Jul 2011, 07:46

exVar[9]={0,0,0,0,0,0,0,0,0};
player[9]={0,'PLAYER_1','PLAYER_2','PLAYER_3','PLAYER_4','PLAYER_5','PLAYER_6','PLAYER_7','PLAYER_8'};

function infiniteTurn(set)
local enabled=0;
if set~=nil then enabled=1;
while not nil do
if enabled==1 then
for i=1,8 do
checkExist(i);
sleep(200);
if exVar==1 then
AddMPtoAllHeroesForPlayer(player[pid]);
end;
end;
end;
end;
end;
end;

function checkExist(pid)
local x=GetPlayerHeroes(player[pid]);
if x~=nil then
for i=0, length(x) do
if IsObjectExist(x) then
exVar[pid]=1;
end;
end;
end;
end;

function AddMPtoAllHeroesForPlayer(pid)
local x=GetPlayerHeroes(pid);
for i=0,length(x) do
ChangeHeroStat(x, STAT_MOVE_POINTS, 10000);
end;
end;


this is the whole script, the error i get is: Value was NIL when getting variable with 'exVar'

I have tried changing variable names, but it didn't help, the script is for HoMM V:ToTE

Franzy
War Dancer
War Dancer
Posts: 362
Joined: 07 Sep 2007
Location: Moscow, Russia
Contact:

Unread postby Franzy » 26 Jul 2011, 04:53

Array constants like these
exVar[9]={0,0,0,0,0,0,0,0,0};
should look like
exVar={0,0,0,0,0,0,0,0,0};

In-game constants like PLAYER_1 should NOT be taken in '.

Your function here
function infiniteTurn(set)
local enabled=0;
if set~=nil then enabled=1;
while not nil do
if enabled==1 then
for i=1,8 do
checkExist(i);
sleep(200);
if exVar==1 then
AddMPtoAllHeroesForPlayer(player[pid]);
end;
end;
end;
end;
end;
end;

is poorly formed and has an error.

I guess you can combine all your functions into just one:

Code: Select all

function infiniteTurn(set) 
local hnum,i,j
 if set~=nil then 
   for i=1,8 do
     hnum = GetPlayerHeroes(i)
     if hnum~=nil then
        for j=0,length(hnum) do  --check if indexing starts from 0, not sure about that
        ChangeHeroStat(hnum[j], STAT_MOVE_POINTS, 10000);
        end; --for
     end; --if
   end; --for
 end; --if
end; --function


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 0 guests