MODULE: Easy mirrors 2.0

Started by Monsieur OUXX, Thu 11/07/2013 10:24:45

Previous topic - Next topic

Akril15

#40
I've got a large game with several mirrors located in various rooms (only one per room, max), and for some reason, one of my game's beta testers is reporting this error when entering rooms with a mirror:

QuoteA fatal error has been generated by the script using the AbortGame function. Please contact the game's author for support.

Error: ERROR: Mirrors::NewMirror : Bad Scripting! you've declared the same mirror twice

I'm not sure what's causing this, as I'm using the same scripting used in the demo game. How can I fix this?

EDIT: Here's what the script in one of my rooms looks like:
Quotebool mirrorsCreated = false;

function room_Load()
{
    if (!mirrorsCreated) {
  Mirrors2.NewMirror(oTest, oTest, region[11], eSymmetryNone, 0.5, 10.0, 0, -310);
  Mirrors2.SetSubstituteCharacter(oTest, cCReflect);
  mirrorsCreated = true;
  }
  Mirrors2.EnableMirror(oTest);
///
}

Khris

So this is happening to only one beta tester? Not the others?

From the module's code and the fact that you're only using one mirror per room, I don't see what could cause this error.
An easy way to cause the error is to create two mirrors and pass the same object as the first parameter.
But you're not doing that in the code you posted.

Akril15

The other beta testers haven't progressed to the spot where the first tester gets the error yet. The only way I was able to "fix" the problem for that tester was by hiding these lines in the module:
Quoteif (findMirror(mask)>= 0)
AbortGame("ERROR: Mirrors::NewMirror : Bad scripting! you've declared the same mirror twice");
But I'm afraid that's going to cause other problems eventually.

Crimson Wizard

#43
@Akril15 do you have mirrors in multiple rooms?
Do you remove created mirrors in Room Leave event?

I never used this module, but the common way of dealing with anything dynamically created is to create on room load and remove on room leave.

Akril15

Quote from: Crimson Wizard on Thu 25/07/2024 19:18:21@Akril15 do you have mirrors in multiple rooms?
Do you remove created mirrors in Room Leave event?
Yes, I have mirrors in multiple rooms, and I tried to remove the mirrors in Room Leave with Mirrors2.DisableAllMirrors();, but that didn't make any difference. It's my understanding that the mirrors are supposed to automatically be unloaded when leaving a room with one or more in it, but that doesn't seem to have happened here.


Eon_Star

Hi. Akril15 can you send a link to your game file? Maybe we can take a look and tell what the problem might be. Thanks.

Khris

@Akril15

This is a bug in the module.

Line 144 is this:
Code: ags
static void Mirrors2::NewMirror( Object* mask,  //set to null if no mask

This means it is valid to pass "null" as the first parameter. However as soon as you create a second mirror with no object anywhere in your game, the module mistakenly thinks you're reusing the object, and there's additional bugs further down where the modules assumes that mask is always != null.

If you always pass an object as first parameter, the module also wrongly assumes you're reusing an object if it has the same ID as a previous mirror's mask object. That's because the module stores a pointer to the room object, which is just a pointer to "object[1]" for instance; an array which gets reused for the new room's objects.

The Demo game happens to use object #0 in the harbor room and objects #1, #2 and #3 in the crystals room, which is how the bug was accidentally avoided.

To fix the bug, find line 135:
Code: ags
    if (data[i].mask == mask)

Change it to:
Code: ags
    if (mask != null && data[i].mask == mask && data[i].room == player.Room)

Akril15

All right, that's great to hear! Thank you!

Akril15

#48
It's me again. I've run into a bit of a conundrum.

I've got a room which two characters appear in (though never at the same time). The problem is that after one character enters and exits this room with a mirror in it, the other character's reflection in that room won't work. It appears at the top of the screen stuck in a standing position, shrinking and growing as the character shrinks and grows and moving left to right as the character does. I've tried everything I can think of to fix this, but so far, nothing's worked. The first character's reflection works fine, but the second one's is entirely broken.

Here's what my script in EntersRoomFirstTime looks like:
Code: ags
if (!mirrorsCreated) {
  Mirrors2.NewMirror(oTestK, oTestK, region[13], eSymmetryNone, 0.5, 10.0, 0, -100);
  if (cCassima==player) Mirrors2.SetSubstituteCharacter(oTestK, cCasReflect);
  if (cEdgar==player) Mirrors2.SetSubstituteCharacter(oTestK, cEdRef);
  mirrorsCreated = true;
  }
  Mirrors2.EnableMirror(oTestK);

What do I do to get this second reflection to behave properly (short of creating a duplicate of this room just to get around this issue)?

EDIT: I finally figured it out. I just had to put the if statements outside of if (!mirrorsCreated).

SMF spam blocked by CleanTalk