3 clicks kills the game

Started by Jordanowen42, Sat 01/03/2025 05:09:28

Previous topic - Next topic

Jordanowen42

Hello all-

I'm trying to set up a simple function where the graphic for a button changes every time I click on it. Clicking on the button three times kills the game. Here's the code:

Code: ags


function oObject20_AnyClick()
{
if (object[20].Graphic == 410)
{object[20].Graphic = 411;
return;}

if (object[20].Graphic == 411)
{object[20].Graphic = 412;
return;}

if (object[20].Graphic == 412)
{object[20].Graphic = 413;
return;}

if (object[20].Graphic == 413)
{object[20].Graphic = 410;
return;}
}

function oObject21_AnyClick()
{
if (object[21].Graphic == 410)
{object[21].Graphic = 411;
return;}

if (object[21].Graphic == 411)
{object[21].Graphic = 412;
return;}

if (object[21].Graphic == 412)
{object[21].Graphic = 413;
return;}

if (object[21].Graphic == 413)
{object[21].Graphic = 410;
return;}
}

function oObject22_AnyClick()
{
if (object[22].Graphic == 410)
{object[22].Graphic = 411;
return;}

if (object[22].Graphic == 411)
{object[22].Graphic = 412;
return;}

if (object[22].Graphic == 412)
{object[22].Graphic = 413;
return;}

if (object[22].Graphic == 413)
{object[22].Graphic = 410;
return;}
}


When the game crashes here's what I get:

---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x0048A5F7; program pointer is +72, engine version 3.6.0.48, gtags (0,0)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and contact the game author for support or post these details on the AGS Technical Forum.



Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK   
---------------------------

Jordanowen42

UPDATE: Nevermind. I figured it out. You guys are nice to put up with me.

Crimson Wizard

Please tell what it was, this is very important for me. Any error message with "Illegal exception" means a bad bug in the engine, that I must fix.

Khris

#3
Here's a shorter version:

Code: ags
function oObject20_AnyClick()
{
  object[20].Graphic = (object[20].Graphic - 409) % 4 + 410;
}

(Iterating over 0 to X is done by adding 1 followed by mod X+1. Iterating over 410 to 413 means we need to subtract 410 first, then add it back at the end.)

You can also do this instead:
Code: ags
  int slot = object[20].Graphic + 1;
  if (slot == 414) slot = 410;
  object[20].Graphic = slot;

The rule of thumb is: if you have lots of similar code you're copy-pasting all over the place, you're probably doing it wrong.

Jordanowen42

Quote from: Crimson Wizard on Sat 01/03/2025 09:51:10Please tell what it was, this is very important for me. Any error message with "Illegal exception" means a bad bug in the engine, that I must fix.

Not your issue- I was asking the program to switch to a room that didn't exist yet.

Crimson Wizard

#5
Quote from: Jordanowen42 on Mon 10/03/2025 06:04:30
Quote from: Crimson Wizard on Sat 01/03/2025 09:51:10Please tell what it was, this is very important for me. Any error message with "Illegal exception" means a bad bug in the engine, that I must fix.

Not your issue- I was asking the program to switch to a room that didn't exist yet.

Thank you.
That is still my issue. The error message "Illegal exception" means that the engine is doing something wrong.
Under normal circumstance, even if the game has mistakes, the engine must display a simple message stating the problem that a regular user can understand, and close itself. "Illegal exception" means that the operating system have aborted the program because it tried to perform a forbidden operation. This has to be fixed.

EDIT:
I made a test in the same version, and changing to a non-existant room does not cause "Illegal exception", it makes engine simply tell that such room does not exist. Looking at your code posted above, I don't see any room change command either. There had to be something else having an effect there.

Jordanowen42

Quote from: Crimson Wizard on Mon 10/03/2025 12:00:35
Quote from: Jordanowen42 on Mon 10/03/2025 06:04:30
Quote from: Crimson Wizard on Sat 01/03/2025 09:51:10Please tell what it was, this is very important for me. Any error message with "Illegal exception" means a bad bug in the engine, that I must fix.

Not your issue- I was asking the program to switch to a room that didn't exist yet.

Thank you.
That is still my issue. The error message "Illegal exception" means that the engine is doing something wrong.
Under normal circumstance, even if the game has mistakes, the engine must display a simple message stating the problem that a regular user can understand, and close itself. "Illegal exception" means that the operating system have aborted the program because it tried to perform a forbidden operation. This has to be fixed.

EDIT:
I made a test in the same version, and changing to a non-existant room does not cause "Illegal exception", it makes engine simply tell that such room does not exist. Looking at your code posted above, I don't see any room change command either. There had to be something else having an effect there.

I wish I could be more help- I'm a rank amateur in this world. :/

Kara Jo Kalinowski

Quote from: Jordanowen42 on Sat 01/03/2025 05:31:07UPDATE: Nevermind. I figured it out. You guys are nice to put up with me.


Could you still let us know what the problem was in case there's a bug in the engine that needs to be fixed?

Crimson Wizard

Well, judging by the error message it's 3.6.0.48, an older version (and not the latest patch of 3.6.0), there's a chance the bug got fixed in the later patches or newer versions. I understand that it may be difficult to figure out which changes exactly fixed the problem in the game, and maybe it's too late to trace these changes back.

SMF spam blocked by CleanTalk