Pages: 1
  Print  
Author Topic: Something wrong with "with"  (Read 10259 times)
Offline (Unknown gender) Woffelson
Posted on: January 29, 2016, 03:02:26 pm

Member
Location: Finland
Joined: Aug 2015
Posts: 9

View Profile
I managed to get working with some simple engine of my Game Maker project. However, now I have following situation:

  • There is two rooms: menu and "battlefield".
  • There is one persistent manager-object (or something like that, controls global events and stuff).
  • Player object is working when it is placed manually in room editor.
  • What is not working anymore is that the mentioned control-object should create the players/bots.

Original part of the code:
Code: [Select]
else if !instance_exists(o_pla)
{
    with instance_create(64,200,o_pla)
    {
        side = 0;
        player = other.player_2;
        spede = other.p2[1];
        jumpspeed = other.p2[2];
        force = other.p2[3];
        sprite_index = other.p2[4];
    }
    with instance_create(560,200,o_pla)
    {
        side = 1;
        player = other.player_1;
        spede = other.p1[1];
        jumpspeed = other.p1[2];
        force = other.p1[3];
        sprite_index = other.p1[4];
    }
}

All help is appreciated. This is the first time I'm trying to do something "real" with Enigma/LGM.

EDIT: Further testing showed that creating works when I exclude lines using "other". So, there is something different how with() works in Enigma...
« Last Edit: January 29, 2016, 03:33:01 pm by Woffelson » Logged
Offline (Male) Goombert
Reply #1 Posted on: January 29, 2016, 07:19:42 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
Hey wolffelson! There is something different about how with() works in ENIGMA. I can't actually tell you, being more the LGM maintainer, but I believe there are currently issues with it in ENIGMA. Josh would be able to tell you more about it. However, I don't think this is actually related to with, but rather, I think it might be a problem with object locals. Try moving instance_create calls into a local variable and use the local variable for the with() first. Also I don't think other would be defined in the create event, unless I misunderstand how GM works, have you tested to see if it works in GM?

Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Woffelson
Reply #2 Posted on: January 30, 2016, 05:30:35 am

Member
Location: Finland
Joined: Aug 2015
Posts: 9

View Profile
I tried to make temporary variable (var) and then I also tried local variables. Instances were created but again the "other" was not working. (Neither worked if I replaced other with the temporary or local variables.) And the project I experimented yesterday was corrupted and LGM gave this error. (So, I tried the original project file again today.)

The project I tested worked in Game Maker. Could this problem  happen because I've imported a project made in Game Maker? It's still weird how everything else in the imported project seems to work in Enigma except the with().

EDIT: Now it works! Although the solution is a bit gimmick...
Code: [Select]
else if !instance_exists(o_pla)
{
    var pla1, ps1, pj1, pf1, psp1, pla2, ps2, pj2, pf2, psp2;
    pla1 = player_1;
    ps1 = p1[1];
    pj1 = p1[2];
    pf1 = p1[3];
    psp1 = p1[4];
    pla2 = player_2;
    ps2 = p2[1];
    pj2 = p2[2];
    pf2 = p2[3];
    psp2 = p2[4];
    with (instance_create(64,200,o_pla))
    {
        side = 0;
        player = pla2;
        spede = ps2;
        jumpspeed = pj2;
        force = pf2;
        sprite_index = psp2;
    }
    with (instance_create(560,200,o_pla))
    {
        side = 1;
        player = pla1;
        spede = ps1;
        jumpspeed = pj1;
        force = pf1;
        sprite_index = psp1;
    }
}
So, I got the thing working with this code. But as it can be seen, the solution demands more work compared to previous and there are many other situations where I've used to use "other" or such. It would be a lot simpler if the referring would work. I don't even know would it be possible to get following line of code working if referring to another object's variable doesn't work:
Code: [Select]
inst.helth -= hit - inst.defense;
« Last Edit: January 30, 2016, 06:41:27 am by Woffelson » Logged
Offline (Male) Goombert
Reply #3 Posted on: January 30, 2016, 10:57:26 am

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
No it has nothing to do with importing the project from GM, it would occur if it was made in ENIGMA anyway. What you have identified is a legitimate bug in ENIGMA's compiler. It's likely the case nobody ever considered that corner case for the with() construct and that's why other is not being defined. Josh knows a lot more about with() because I think he had to write it. I'm fairly certain after your tests now that "other" doesn't equal anything, it's not being set basically. A ticket should be filed on ENIGMA's tracker with a SSCCE, an isolated test case not your whole game, so that it can be fixed. I will do this for you later today when I have time.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1
  Print