Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Call function from other function: Access violation [Solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
paul44
Expert Cheater
Reputation: 3

Joined: 20 Jul 2017
Posts: 214

PostPosted: Fri Jan 09, 2026 1:19 pm    Post subject: Call function from other function: Access violation [Solved] Reply with quote

get an idea here: [ https://ibb.co/mFcS5g8z ]

I think this is standard stuff (or so i thought):
1. the main funtion builds a list of items, which get shown in a Listbox
2. that same form offers an option/button to change a particular value in these items; iow 'setLevel()' is called upon clicking this button
3. setLevel: parkours the Listbox, and updates each item's value (this part works fine and dandy)
4. when finished: i'd obviously like to update the listbox visually... which basically means re-run the main script 'CollectInventory()' again
=> since this is a particular list, the choice needs to be passed on as well.

I've also tried: local vs global, and placing subfunction inside main function

Fyi: i do have a workaround; basically getting each line, edit as string and then update the listbox accordingly...
(but above approach should work somehow as well ?!)

Strange thing is: i (vaguely) recall having done this for another game; but just can't remember which one

ps: i'm using CE v7.3 here, but also tried with 7.6 (kinda hoping it would give me a more specific error_definition)


Last edited by paul44 on Sat Jan 10, 2026 2:37 am; edited 1 time in total
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1548

PostPosted: Fri Jan 09, 2026 5:59 pm    Post subject: Reply with quote

I think the problem seems to be confusing the order in which you use what isn't there.

It's healthier to assign it above and use it in the lines below.

That's the difference between Lua and CE Lua, I guess.

Test these:

Code:
local f = nil
local nChoice = 0
local sListItems
local CollectInventory

function setLevel()



  CollectInventory(2)
end

-- *** main function ***
CollectInventory=function(nFormChoice)
 -- nChoice = nFormChoice or nChoice
--  local addrInventory = getAddress("[pInventory2]")
  if nFormChoice==1 then
    print("I'm here.")
  elseif nFormChoice==2 then
    print("Where am I?")
  else
    print("I'm gone!")


-- (builds a list of items, which get shown in Listbox)

end
--sListItems.endUpdate()
end

nChoice = 1

if (nChoice > 0 and nChoice < 5) then CollectInventory(nChoice) end

setLevel()


If the CollectInventory() function doesn't contain setLevel(), you can use it like this:

Code:
function CollectInventory(nFormChoice) -- Introduce first.
-- ...
end

function setLevel()
-- ...
  CollectInventory(2) -- Then use it.
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
paul44
Expert Cheater
Reputation: 3

Joined: 20 Jul 2017
Posts: 214

PostPosted: Sun Jan 11, 2026 4:43 am    Post subject: stringlist was culprit This post has 1 review(s) Reply with quote

(not sure what happened, but my initial reply got lost in translation somehow ?)

anyways: short version
1. i assumed (wrongly) that the call itself caused the error
2. your 'print' statements made me realize it could actually happen in the main fn itself
3. error: was caused by stringlist; which gets destroyed after main fn ran...

solution:
// ...
sListItems = createStringList()
CollectInventory(2)
sListItems.destroy()
//

ps: i forgive myself for the error being too cryptic Rolling Eyes
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Sat Jan 31, 2026 4:24 pm    Post subject: Reply with quote

This might be the wrong place to ask this question, but here goes anyway.
Suppose I have a main function that has all the code in it for a game.
Code:

function XYZ()
--some code lines that have nothing to do with my question but control the game.
function ABC()
--some code that I want to modify game.
end
--miscellaneous code.
function CheckDay()
if day == 1 then
--miscellaneous code.
--Now my question I want to call function ABC.  I thought that the way to do --this was
ABC
end
end

What the error code returns is "last line read ABC expected "="" and the whole code crashes.
So what is the proper way to call a function?
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1548

PostPosted: Mon Feb 02, 2026 8:34 am    Post subject: Reply with quote

bknight2602 wrote:
This might be the wrong place to ask this question, but here goes anyway.
Suppose I have a main function that has all the code in it for a game.
Code:

function XYZ()
--some code lines that have nothing to do with my question but control the game.
function ABC()
--some code that I want to modify game.
end
--miscellaneous code.
function CheckDay()
if day == 1 then
--miscellaneous code.
--Now my question I want to call function ABC.  I thought that the way to do --this was
ABC
end
end

What the error code returns is "last line read ABC expected "="" and the whole code crashes.
So what is the proper way to call a function?



I'm assuming the code contains functions that run within the CE Lua script, not the game itself, and it's normal for the plain "ABC" you're using to give an error.

Instead, you should use "ABC()" for the "Execute Function".

You can test the example code below independently by activating it in a separate CE Lua script window and pressing F10, or you can simply look at the code to see how it works.

Code:
-- run ABC test ..
local day = 1

function ABC()
  print("(ABC func) day: "..day)
end
--miscellaneous code.
function CheckDay()
  if day == 1 then
    ABC()
  else
    print("(CheckDay func) day: "..day)
  end
  day = day + 1
  if day==3 then day=1 end
end

if dayKey then dayKey.Destroy() dayKey=nil end
dayKey = createHotkey(CheckDay, VK_F10)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Sat Feb 07, 2026 2:34 pm    Post subject: Reply with quote

I had tried that but alas that has an error also, attempt to call a nil value. Let me provide some code and yes the code for LUA controls the game as you suspected. It is a long bit of code. The function that has a "nil" value when called is on line 289, the call is line 452. The game is Heroes of might and magic V. If I comment the AddSki8lls() the code runs.
Code:

town_array = {"T1","T2","T3","T4", "T5","T6","T7","T8"};
town_array.n = 8;
count = 0;
countx= 0;

y = GetPlayerHeroes(1);
h1 = y[0];
a = GetPlayerHeroes(2);
h2 = a[0];

function TownCounter1()
   print("Towncount of player1 = ",Town_count1(),"   with main hero:",h1 );
   print(h1);
   if Town_count1() == 8 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,610350);
   elseif Town_count1() == 7 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,244140);
      SetAIPlayerAttractor("T8", 1, 1);
   elseif Town_count1() == 6 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,97650);
      SetAIPlayerAttractor("T7", 1, 1);
   elseif Town_count1() == 5 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,39060);
      SetAIPlayerAttractor("T6", 1, 1);
   elseif Town_count1() == 4 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,15620);
      SetAIPlayerAttractor("T5", 1, 1);
   elseif Town_count1() == 3 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,6250);
      SetAIPlayerAttractor("T4", 1, 1);
   elseif Town_count1() == 2 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,2500);
      SetAIPlayerAttractor("T3", 1, 1);
      print("hero1 166exp");
   elseif Town_count1() == 1 and IsHeroAlive(h1) == 1 then
      ChangeHeroStat(h1,0,1000);
      SetAIPlayerAttractor("T2", 1, 1);
      print(" hero1  50exp");
   end;
end;

function Town_count1()
   count = 0;
   for i=1, town_array.n do
      if ( GetObjectOwner(town_array[i]) == PLAYER_1 ) then
         count = count + 1;
      end;
   end;
   return count;
end;

function TownCounter2()
   print( "Towncount of player2 = ",Town_count2(),"   with mainhero:", h2 );
   if Town_count2() == 8 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,61035);
   elseif Town_count2() == 7 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,24414);
      SetAIPlayerAttractor("T8", 2, 1);
   elseif Town_count2() == 6 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,9765);
      SetAIPlayerAttractor("T7", 2, 1);
   elseif Town_count2() == 5 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,3096);
      SetAIPlayerAttractor("T6", 2, 1);
   elseif Town_count2() == 4 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,1562);
      SetAIPlayerAttractor("T5", 2, 1);
   elseif Town_count2() == 3 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,625);
      SetAIPlayerAttractor("T4", 2, 1);
   elseif Town_count2() == 2 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,250);
      SetAIPlayerAttractor("T3", 2, 1);
   elseif Town_count2() == 1 and IsHeroAlive(h2) == 1 then
      ChangeHeroStat(h2,0,100);
      SetAIPlayerAttractor("T2", 2, 1);
   end;
end;

function Town_count2()
   countx = 0;
   for i=1, town_array.n do
      if ( GetObjectOwner(town_array[i]) == PLAYER_2 ) then
         countx = countx + 1;
      end;
   end;
   return countx;
end;

function SwitchTown1()
   if GetObjectOwner("T1") == 2 then
      TransformTown("T1", 4);
   end;
end;

function SwitchTown2()
   if GetObjectOwner("T2") == 1 then
      TransformTown("T2", 0);
      print("T2 = heaven");
   elseif GetObjectOwner("T2") == 2 then --and GetObjectOwner("T7") == 2 and GetObjectOwner("T6") == 2 and GetObjectOwner("T5") == 2 and GetObjectOwner("T4") == 2 and GetObjectOwner("T3") == 2 then
      TransformTown("T2", 4);
      print("T2 = necro");
   end;
end;

function SwitchTown3()
   if GetObjectOwner("T3") == 1 then
      TransformTown("T3", 0);
      print("T3 = heaven");
   elseif GetObjectOwner("T3") == 2 then --and GetObjectOwner("T7") == 2 and GetObjectOwner("T6") == 2 and GetObjectOwner("T5") == 2 and GetObjectOwner("T4") == 2 then
      TransformTown("T3", 4);
      print("t3 = necro");
   end;
end;

function SwitchTown4()
   if GetObjectOwner("T4") == 1 then --and GetObjectOwner("T2") == 1 and GetObjectOwner("T3") == 1 then
      TransformTown("T4", 0);
      print("T4=Heaven");
   elseif GetObjectOwner("T4") == 2 then --and GetObjectOwner("T7") == 2 and GetObjectOwner("T6") == 2 then
      TransformTown("T4", 4);
      print("T4 = Necro");
   end;
end;

function SwitchTown5()
   if GetObjectOwner("T5") == 1 then --and GetObjectOwner("T2") == 1 and GetObjectOwner("T3") == 1 then
      TransformTown("T5", 0);
      print("T5=Heaven");
   elseif GetObjectOwner("T5") == 2 then --and GetObjectOwner("T7") == 2 and GetObjectOwner("T6") == 2 then
      TransformTown("T5", 4);
      print("T5 = Necro");
   end;
end;

function SwitchTown6()
   if GetObjectOwner("T6") == 1 then --and GetObjectOwner("T2") == 1 and GetObjectOwner("T3") == 1 and GetObjectOwner("T4") == 1 and GetObjectOwner("T5") == 1 then
      TransformTown("T6", 0);
      print("T6=Heaven");
   elseif GetObjectOwner("T6") == 2 then --and GetObjectOwner("T7") == 2 then
      TransformTown("T6", 4);
      print("T6 = Necro");
   end;
end;

function SwitchTown7()
   if GetObjectOwner("T7") == 1 then --and GetObjectOwner("T2") == 1 and GetObjectOwner("T3") == 1 and GetObjectOwner("T4") == 1 and GetObjectOwner("T5") == 1 and GetObjectOwner("T6") == 1 then
      TransformTown("T7", 0);
      print("T7=Heaven");
   elseif GetObjectOwner("T7") == 2 then
      TransformTown("T7", 4);
      print("T7 = Necro");
   end;
end;

function SwitchTown8()
   if GetObjectOwner("T8") == 1 then
      TransformTown("T8", 0);
   end;
end;



Trigger(OBJECT_CAPTURE_TRIGGER, "T1", "SwitchTown1")
Trigger(OBJECT_CAPTURE_TRIGGER, "T2", "SwitchTown2")
Trigger(OBJECT_CAPTURE_TRIGGER, "T3", "SwitchTown3")
Trigger(OBJECT_CAPTURE_TRIGGER, "T4", "SwitchTown4")
Trigger(OBJECT_CAPTURE_TRIGGER, "T5", "SwitchTown5")
Trigger(OBJECT_CAPTURE_TRIGGER, "T6", "SwitchTown6")
Trigger(OBJECT_CAPTURE_TRIGGER, "T7", "SwitchTown7")
Trigger(OBJECT_CAPTURE_TRIGGER, "T8", "SwitchTown8")


Trigger(NEW_DAY_TRIGGER,"Test");
function Test()
   y = GetPlayerHeroes(1);
   h1 = y[0];
   a = GetPlayerHeroes(2);
   h2 = a[0];
   print(count);
   print(countx);
   TownCounter1()
   TownCounter2()
function reducecount()
   startnumberofheroes = startnumberofheroes - 1
end;
   playernames = GetPlayerHeroes(PLAYER_1);
   print("Firstfunction");
   for i = 0, length(playernames) - 1 do --startnumberofheroes, length(playernames) - 1 do
      GiveHeroSkill(playernames[i], 74);
      GiveHeroSkill(playernames[i], 88);
      GiveHeroSkill(playernames[i], 139);
      GiveHeroSkill(playernames[i], 100);
      GiveHeroSkill(playernames[i], 126);
      GiveHeroSkill(playernames[i], 22);
      GiveHeroSkill(playernames[i], 23);
      GiveHeroSkill(playernames[i], 24);
      GiveHeroSkill(playernames[i], 25);
      GiveHeroSkill(playernames[i], 34);
      GiveHeroSkill(playernames[i], 35);
      GiveHeroSkill(playernames[i], 130);
      GiveHeroSkill(playernames[i], 117);
      GiveHeroSkill(playernames[i], 104);
      GiveHeroSkill(playernames[i], 91);
      GiveHeroSkill(playernames[i], 76);
      GiveHeroSkill(playernames[i], 36);
      GiveHeroSkill(playernames[i], 38);
      GiveHeroSkill(playernames[i], 39);
      GiveHeroSkill(playernames[i], 118);
      GiveHeroSkill(playernames[i], 144);
      GiveHeroSkill(playernames[i], 131);
      GiveHeroSkill(playernames[i], 105);
      GiveHeroSkill(playernames[i], 37);
      GiveHeroSkill(playernames[i], 44);
      GiveHeroSkill(playernames[i], 82);
      GiveHeroSkill(playernames[i], 146);
      GiveHeroSkill(playernames[i], 133);
      GiveHeroSkill(playernames[i], 120);
      GiveHeroSkill(playernames[i], 94);
      GiveHeroSkill(playernames[i], 43);
      GiveHeroSkill(playernames[i], 45);
      GiveHeroSkill(playernames[i], 40);
      GiveHeroSkill(playernames[i], 41);
      GiveHeroSkill(playernames[i], 42);
      GiveHeroSkill(playernames[i], 81);
      GiveHeroSkill(playernames[i], 93);
      GiveHeroSkill(playernames[i], 119);
      GiveHeroSkill(playernames[i], 132);
      GiveHeroSkill(playernames[i], 145);
      GiveHeroSkill(playernames[i], 138);
      GiveHeroSkill(playernames[i], 112);
      GiveHeroSkill(playernames[i], 73);
      GiveHeroSkill(playernames[i], 19);
      GiveHeroSkill(playernames[i], 20);
      GiveHeroSkill(playernames[i], 21);
      GiveHeroSkill(playernames[i], 86);
      GiveHeroSkill(playernames[i], 125);
      GiveHeroSkill(playernames[i], 28);
      GiveHeroSkill(playernames[i], 29);
      GiveHeroSkill(playernames[i], 30);
      GiveHeroSkill(playernames[i], 115);
      GiveHeroSkill(playernames[i], 75);
      GiveHeroSkill(playernames[i], 89);
      GiveHeroSkill(playernames[i], 128);
      GiveHeroSkill(playernames[i], 141);
      GiveHeroSkill(playernames[i], 116);
      GiveHeroSkill(playernames[i], 129);
      GiveHeroSkill(playernames[i], 142);
      GiveHeroSkill(playernames[i], 31);
      GiveHeroSkill(playernames[i], 32);
      GiveHeroSkill(playernames[i], 33);
      GiveHeroSkill(playernames[i], 80);
      GiveHeroSkill(playernames[i], 46);
      GiveHeroSkill(playernames[i], 47);
      GiveHeroSkill(playernames[i], 48);
      GiveHeroSkill(playernames[i], 95);
      GiveHeroSkill(playernames[i], 121);
      GiveHeroSkill(playernames[i], 134);
      GiveHeroSkill(playernames[i], 147);
      GiveHeroSkill(playernames[i], 49);
      GiveHeroSkill(playernames[i], 50);
      GiveHeroSkill(playernames[i], 51);
      GiveHeroSkill(playernames[i], 81);
      GiveHeroSkill(playernames[i], 78);
      GiveHeroSkill(playernames[i], 96);
      GiveHeroSkill(playernames[i], 109);
      GiveHeroSkill(playernames[i], 122);
      GiveHeroSkill(playernames[i], 135);
      GiveHeroSkill(playernames[i], 148);
      GiveHeroSkill(playernames[i], 52);
      GiveHeroSkill(playernames[i], 53);
      GiveHeroSkill(playernames[i], 54);
      GiveHeroSkill(playernames[i], 84);
      GiveHeroSkill(playernames[i], 97);
      GiveHeroSkill(playernames[i], 110);
      GiveHeroSkill(playernames[i], 123);
      GiveHeroSkill(playernames[i], 136);
      GiveHeroSkill(playernames[i], 163);
      GiveHeroSkill(playernames[i], 169);
      ChangeHeroStat(playernames[i],0,50000);
      ChangeHeroStat(playernames[i],1,1);
      ChangeHeroStat(playernames[i],2,1);
      ChangeHeroStat(playernames[i],3,1);
      ChangeHeroStat(playernames[i],4,1);
      print(playernames[i]);
   end;
   startnumberofheroes = length(playernames);
--end;
function AddSkills()
   print("In call");
   print(GetDate(DAY));
      for x = 36, 43 do
         if HasArtefact(playernames[i], x) ~= 1 then
            GiveArtefact(playernames[i], x);
         end;
      end;
      if HasArtefact(playernames[i],22) ~= 1 then
         GiveArtefact(playernames[i],22);
      end;
      if HasArtefact(playernames[i],25) ~= 1 then
         GiveArtefact(playernames[i],25);
      end
      ChangeHeroStat(playernames[i], 1, 15);
      ChangeHeroStat(playernames[i], 2, 10);
      ChangeHeroStat(playernames[i], 3, 10);
      ChangeHeroStat(playernames[i], 4, 10);
      ChangeHeroStat(playernames[i], 8, 50);
      for x = 1, 3 do
         GiveHeroSkill(playernames[i], 2);
         GiveHeroSkill(playernames[i], 3);
         GiveHeroSkill(playernames[i], 6);
         GiveHeroSkill(playernames[i], 7);
         GiveHeroSkill(playernames[i], 9);
         GiveHeroSkill(playernames[i], 1);
         GiveHeroSkill(playernames[i], 4);
         GiveHeroSkill(playernames[i], 5);
         GiveHeroSkill(playernames[i], 8);
         GiveHeroSkill(playernames[i], 10);
         GiveHeroSkill(playernames[i], 11);
         GiveHeroSkill(playernames[i], 12);
      end;
      GiveHeroWarMachine(playernames[i], 1);
      GiveHeroWarMachine(playernames[i], 3);
      GiveHeroWarMachine(playernames[i], 4);
      GiveHeroSkill(playernames[i], 74);
      GiveHeroSkill(playernames[i], 88);
      GiveHeroSkill(playernames[i], 139);
      GiveHeroSkill(playernames[i], 100);
      GiveHeroSkill(playernames[i], 126);
      GiveHeroSkill(playernames[i], 22);
      GiveHeroSkill(playernames[i], 23);
      GiveHeroSkill(playernames[i], 24);
      GiveHeroSkill(playernames[i], 25);
      GiveHeroSkill(playernames[i], 34);
      GiveHeroSkill(playernames[i], 35);
      GiveHeroSkill(playernames[i], 130);
      GiveHeroSkill(playernames[i], 117);
      GiveHeroSkill(playernames[i], 104);
      GiveHeroSkill(playernames[i], 91);
      GiveHeroSkill(playernames[i], 76);
      GiveHeroSkill(playernames[i], 36);
      GiveHeroSkill(playernames[i], 38);
      GiveHeroSkill(playernames[i], 39);
      GiveHeroSkill(playernames[i], 118);
      GiveHeroSkill(playernames[i], 144);
      GiveHeroSkill(playernames[i], 131);
      GiveHeroSkill(playernames[i], 105);
      GiveHeroSkill(playernames[i], 37);
      GiveHeroSkill(playernames[i], 44);
      GiveHeroSkill(playernames[i], 82);
      GiveHeroSkill(playernames[i], 146);
      GiveHeroSkill(playernames[i], 133);
      GiveHeroSkill(playernames[i], 120);
      GiveHeroSkill(playernames[i], 94);
      GiveHeroSkill(playernames[i], 43);
      GiveHeroSkill(playernames[i], 45);
      GiveHeroSkill(playernames[i], 40);
      GiveHeroSkill(playernames[i], 41);
      GiveHeroSkill(playernames[i], 42);
      GiveHeroSkill(playernames[i], 81);
      GiveHeroSkill(playernames[i], 93);
      GiveHeroSkill(playernames[i], 119);
      GiveHeroSkill(playernames[i], 132);
      GiveHeroSkill(playernames[i], 145);
      GiveHeroSkill(playernames[i], 138);
      GiveHeroSkill(playernames[i], 112);
      GiveHeroSkill(playernames[i], 73);
      GiveHeroSkill(playernames[i], 19);
      GiveHeroSkill(playernames[i], 20);
      GiveHeroSkill(playernames[i], 21);
      GiveHeroSkill(playernames[i], 86);
      GiveHeroSkill(playernames[i], 125);
      GiveHeroSkill(playernames[i], 28);
      GiveHeroSkill(playernames[i], 29);
      GiveHeroSkill(playernames[i], 30);
      GiveHeroSkill(playernames[i], 115);
      GiveHeroSkill(playernames[i], 75);
      GiveHeroSkill(playernames[i], 89);
      GiveHeroSkill(playernames[i], 128);
      GiveHeroSkill(playernames[i], 141);
      GiveHeroSkill(playernames[i], 116);
      GiveHeroSkill(playernames[i], 129);
      GiveHeroSkill(playernames[i], 142);
      GiveHeroSkill(playernames[i], 31);
      GiveHeroSkill(playernames[i], 32);
      GiveHeroSkill(playernames[i], 33);
      GiveHeroSkill(playernames[i], 80);
      GiveHeroSkill(playernames[i], 46);
      GiveHeroSkill(playernames[i], 47);
      GiveHeroSkill(playernames[i], 48);
      GiveHeroSkill(playernames[i], 95);
      GiveHeroSkill(playernames[i], 121);
      GiveHeroSkill(playernames[i], 134);
      GiveHeroSkill(playernames[i], 147);
      GiveHeroSkill(playernames[i], 49);
      GiveHeroSkill(playernames[i], 50);
      GiveHeroSkill(playernames[i], 51);
      GiveHeroSkill(playernames[i], 81);
      GiveHeroSkill(playernames[i], 78);
      GiveHeroSkill(playernames[i], 96);
      GiveHeroSkill(playernames[i], 109);
      GiveHeroSkill(playernames[i], 122);
      GiveHeroSkill(playernames[i], 135);
      GiveHeroSkill(playernames[i], 148);
      GiveHeroSkill(playernames[i], 52);
      GiveHeroSkill(playernames[i], 53);
      GiveHeroSkill(playernames[i], 54);
      GiveHeroSkill(playernames[i], 84);
      GiveHeroSkill(playernames[i], 97);
      GiveHeroSkill(playernames[i], 110);
      GiveHeroSkill(playernames[i], 123);
      GiveHeroSkill(playernames[i], 136);
      GiveHeroSkill(playernames[i], 169);
      GiveHeroSkill(playernames[i], 163);
      ChangeHeroStat(playernames[i], 0, 170000);
      for x = 1, 15 do
         TeachHeroSpell(playernames[i], x);
      end;
      for x = 17, 21 do
         TeachHeroSpell(playernames[i], x);
      end;
      for x = 23, 26 do
         TeachHeroSpell(playernames[i], x);
      end;
      for x = 28, 29 do
         TeachHeroSpell(playernames[i], x);
      end;
      for x = 38, 43 do
         TeachHeroSpell(playernames[i], x);
      end;
      for x = 48, 51 do
         TeachHeroSpell(playernames[i], x);
      end;
      for x = 35, 35 do
         TeachHeroSpell(playernames[i], x);
      end;
      MakeHeroReturnToTavernAfterDeath(playernames[i], not nil, 1);
      --addperks(playernames[i]);
      --print(playernames[i]);
      print(playernames[i]);  --Print the name whose skills altered
   end;
   startnumberofheroes = length(playernames);
end;
if GetDate(DAY) == 1 then
   for x = 0, 6 do
      if x < 6 then
      SetPlayerResource(PLAYER_1, x, 1000);
      else SetPlayerResource(PLAYER_1, x, 100000);
      end;
   end;
   startnumberofheroes = 0;
   AddSkills()
end;
print(GetDate(DAY));
print(startnumberofheroes);
print(length(GetPlayerHeroes(PLAYER_1)));
Trigger(PLAYER_ADD_HERO_TRIGGER,PLAYER_1, "AddSkills");
Trigger(PLAYER_REMOVE_HERO_TRIGGER,PLAYER_1, "reducecount");
Back to top
View user's profile Send private message Yahoo Messenger
paul44
Expert Cheater
Reputation: 3

Joined: 20 Jul 2017
Posts: 214

PostPosted: Sun Feb 08, 2026 2:22 am    Post subject: use "debug prints" Reply with quote

some tips:
1. place several print('here1...') etc in that function. That will allow you to figure out WHEN/WHERE it fails (eventually)
2. which version of CE are you using? normally it'll give you a line_number for that error (~ right-click)
3. CE7.6+ is really good when it comes to reporting (detailed) erroring.
Note: saving in 7.6 means (mostly) that your users will need that version as well...

also: it might very well be that the error actually occurs in that 'trigger' function ?! (~ ce7.6 (almost) certainly will tell you that)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1548

PostPosted: Sun Feb 08, 2026 3:58 am    Post subject: Reply with quote

bknight2602 wrote:
I had tried that but alas that has an error also ...


The error that is apparent at first glance:

Unless it has changed, the following rule applies in CE:
Define first, then call, use!

Wrong:
Code:
print(count)

local count = 1


Correct:
Code:
local count = 1

print(count)


In your case, the following is happening:
Code:
function TownCounter1()
   print("Towncount of player1 = ",Town_count1(),"   with main hero:",h1 );
   print(h1);
   if Town_count1() == 8 and IsHeroAlive(h1) == 1 then -->> nil ! -->>> Town_count1() (Undefined)
---- ...
end

-- It's defined below, but attempts are being made to use it in the lines above ...
function Town_count1()
   count = 0;
   return count;
end;


Try using it like this:

Code:
-- Define:
function Town_count1()
   count = 0;
   return count;
end;

function TownCounter1()
   print("Towncount of player1 = ",Town_count1(),"   with main hero:",h1 );
   print(h1);
   if Town_count1() == 8 and IsHeroAlive(h1) == 1 then -->> success -->>> Town_count1() (Defined at the top!)
---- ...
end


Important note that might seem unrelated:

Please ask your question in a separate thread instead of posting it within someone else's unrelated topic.

Since these types of question and answer exchanges are for "archival" purposes, posting two unrelated topics under one heading could be confusing.

Thank you in advance for your understanding.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites