ENIGMA Forums

Outsourcing saves money => Issues Help Desk => Topic started by: Hoohee on December 18, 2017, 09:42:56 pm

Title: Turning On A Variable Disables Character Movement
Post by: Hoohee on December 18, 2017, 09:42:56 pm
Self-quote, from the other thread:
I may have discovered another bug.  For some reason, turning on a user-defined variable (by holding a button) messes with a character's movement.  The character either stops moving, or moves in weird ways.  I haven't been able to duplicate this in my experiment file (the "Jump" one), but I'll keep trying to figure out what's wrong.  In the meantime, if this helps, the character's movement uses variables as well; the hspeed and vspeed variables in the "Step" event.
Last I checked, this was never solved in the original thread I posted it in.  That's partially my fault.  As I am having this issue in a game I made in GM8 and hope to sell--and was also hoping to port to Enigma--I declined to provide the file.  I attempted to duplicate the bug with a new game specially made to duplicate this issue, but I couldn't.

I'd appreciate all the help I can get in digging up what might be causing this issue.  Admittedly, that might not be too easy without me providing the game, but maybe we can work something out.  Note that I actually can provide the code for the parts of my game that have this problem.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Josh @ Dreamland on December 22, 2017, 06:27:39 pm
You can ignore TKG; he gets that way literally all the time.

It's okay if you don't want to provide the file. Can you provide a small test case that demonstrates what ENIGMA is doing incorrectly?

We can skip that if you provide more details on what variable you're setting. You say "a user-defined variable"—what is its name? It may be interfering with an ENIGMA system variable, or a variable that ENIGMA provides for backward-compatibility. For instance, setting image_single will stop an instance's sprite animation. This behavior was removed from Game Maker, as far as I know.

There are also minor differences in the way ENIGMA handles code. A good example is using a function name as a variable. I doubt you're hitting any of that, based on the fact that your game will start up and run fine.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on January 05, 2018, 08:11:28 pm
I apologize for taking so long to respond to this; I was on a trip.

The variable's name is "Vacuum".  Incidentally, when it loaded up, I also saw this alert:

Quote
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:2279:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
     if(action_if_variable(enigma::varaccess_Vacuum(int(self)), 1, 0))

What are "explicit braces"?
Title: Re: Turning On A Variable Disables Character Movement
Post by: faissaloo on January 06, 2018, 07:54:57 am
I apologize for taking so long to respond to this; I was on a trip.

The variable's name is "Vacuum".  Incidentally, when it loaded up, I also saw this alert:

Quote
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:2279:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
     if(action_if_variable(enigma::varaccess_Vacuum(int(self)), 1, 0))

What are "explicit braces"?
Braces are another name for curly brackets ('{' and '}'). It's telling you that it may have misinterpreted your use of 'else' as meaning something you didn't intend and so you should use curly brackets to clarify this for the compiler.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Josh @ Dreamland on January 06, 2018, 11:29:59 am
To my knowledge, "Vacuum" is not a reserved word... do you have a resource by that name? Are you using that variable in any movement logic? There may be a difference in event execution order that is causing your logic to behave differently in ENIGMA when compared to GM.
Title: Re: Turning On A Variable Disables Character Movement
Post by: hpg678 on January 06, 2018, 02:01:00 pm
i have a theory in mind but before I voice it, could you send the segment of code involving the variable as well an explanation for its use?

Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on January 06, 2018, 04:12:22 pm
Ok; so the bits involving Vacuum aren't text code, but Drag & Drop, but I can provide some things. 


I copied the text that appeared in Debug, and so here are the parts involving Vacuum.
Quote
Add dot accessed local Vacuum
Quote
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:2376:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
     if(action_if_variable(enigma::varaccess_Vacuum(int(self)), 1, 0))
       ^



And as to the Drag & Drop stuff in the actual game.  First for the object that has the vacuum.

In Create:
Quote
Set Vacuum to 0

In Press Q:
Quote
If Fuel is less than 16
If Vacuum is equal to 0
Set variable Vacuum to 1

In Release Q:
Quote
If Vacuum is equal to 1
Set variable Vacuum to 0


Now for the objects that get vacuumed.

In Normal Step:
Quote
If Vacuum is equal to 1. (NOTE: For the other object.)
If at position (x,y) there is an instance of object object_Suction
Start of block
Move towards point (object_Mouth.x,object_Mouth.y)
End of block
Else
Start moving in one of directions 000010000 with speed 4

In Collision with object_Mouth:
Quote
If Vacuum is equal to 1
Start of block
Destroy the instance
Set relative variable Fuel to 1
Set relative variable Fuel to 1
Set the relative score to 1
End of block
Title: Re: Turning On A Variable Disables Character Movement
Post by: hpg678 on January 08, 2018, 08:49:46 am
Sorry it took me a while to answer. I was involved in another issue and it still isn't solved.

I had suspected you were using DRAG N DROP. So now that's settled, let's look at your problem.

First if you haven't done this already, create an object that controls the main processes of the game, (a 'controller object' so to speak,) and in its CREATE event set  'Vacuum' as a global variable.

Code: [Select]
globalvar Vacuum;
Vacuum = 1;

Why give your variable vacuum a value of 1? So as it have a tangible value to start with and the switching will be 'smoother' from 1 to 0 and 0 to 1 or whatever values you give it.

=================================================

for the 'Press Q' event, I would like to erase what you have, place a 'Create Code' icon and write this code
Code: [Select]
if (Fuel < 16) && (Vacuum = 0)
   {
       Vacuum = 1;
   }

It's my understanding that you want to change the value of Vacuum when these two conditions are met, and this is the more direct approach.

That being the case, in the 'Release Q' event your can delete the 'If Vacuum is equal to 1' and just leave the 'Set a Variable' icon present.

===========================================================
At this time, try these changes and tell me the results.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on January 18, 2018, 07:39:58 pm
Thank you, and I think I'm making progress; that is, turning on the variable no longer stops the character from moving.

However, to finish implementing them, I want to double-check whether Enigma still adheres to GM's syntax on global variables; that is, after they're declared, can they be referenced without the word, "global"?
Title: Re: Turning On A Variable Disables Character Movement
Post by: hpg678 on January 19, 2018, 09:22:15 am
Happy to hear of your success.  (Y) (Y)

As far as your other question is concerned, well.....I guess either Goombert or JOSH@Dreamland can help you on the more technical aspects; but as far as I know ENIGMA does.

As far as using 'global' variables are concerned, the surest way of using them would be to to use 'globalvar <variable>' whereby any object can reference that variable from anywhere in the game. This is why I suggested using 'globalvar Vacuum' in your example game.

If I understand the WIKI correctly you can also  have the same effect by declaring them in the 'Globals' section of the ENIGMA subsection in the configuration tool.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on January 20, 2018, 01:52:23 am
Moving along, can I reference global variables with drag and drop?  It seems doing so causes errors.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Josh @ Dreamland on January 22, 2018, 10:40:07 pm
There's no reason you should not be able to. What kind of errors?
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on January 23, 2018, 05:24:30 pm
I'll give the first error as an example.  It's a collision event.  The first D&D item is "If globalvar Vacuum is equal to 1".  These sorts of events must specify what that "applies to"; I've selected Self.  As global variables are not confined to any one object, possibly that's what's causing the error.  At any rate, here is the error:

Quote
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectdeclarations.h:1943:17: warning: inline function 'bool enigma::OBJ_object_Pollen::myevent_collision_5_subcheck()' used but never defined [enabled by default]
     inline bool myevent_collision_5_subcheck();
Title: Re: Turning On A Variable Disables Character Movement
Post by: hpg678 on January 24, 2018, 10:55:08 am
Ok let's talk a little about global variables. According to Gamemaker online manual, using 'global.<variable>' and 'globalvar <variable>' have the same effect. However, experience have shown this not always to be the case. As a global variable, one would expect any object to be able to access it anywhere at anytime in the game. When you use 'global.<variable>', you need to use that prefix every time or the parser will think the variable is local and output errors.
For some reason using 'globalvar <variable>' creates no confusion or errors.

to do this in Drag N Drop, you need to use a 'Add a Code' icon from the Control tab and place it in the Create event. from there you then use just the name of the '<variable>' when it asks for the name of the variable.

Now, concerning your error.
It seems that you've reference a variable which wasn't declared in the object obj_Pollen. You need to check and fix it either as a local variable or a global one.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on January 27, 2018, 06:23:52 pm
I'm getting this error:

Quote
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_globals.h:69:1: error: 'var' is not a template
 var<Vacuum> object_Mouth;

I wasn't sure whether "Vacuum" is supposed to be enclosed in those "greater and lesser" signs.  I've tried it other ways, but all seem to return errors.  Also, can an "If" statement in a block code function on its own in tandem with a Drag & Drop action, or do the condition and action have to be in the same code block?

Edit: For whatever reason, I'm also getting new errors about an action I placed in one object's creation event.  It is supposed to cause another object to get created at its X,Y position, but now I'm getting a message that says:

Quote
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:470:26: error: reference to 'object_Mouth' is ambiguous
     action_create_object(object_Mouth, x, y);
                          ^
In file included from SHELLmain.cpp:107:0:
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_globals.h:69:5: note: candidates are: var object_Mouth
 var object_Mouth;

That is really odd, since so far as I know, there is only one such object.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on February 06, 2018, 03:50:42 am
I'm bumping this to say that I've never gotten this error before, so far as I know.  Why declaring some global variables would cause it, I also don't know.

I also converted everything involving global variables (I think) to code.  Granted, it was GML, so that might not work completely.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Josh @ Dreamland on February 06, 2018, 12:02:42 pm
As you have probably noticed, [snip=edl]var<Vacuum> object_Mouth[/snip] is not valid syntax (well, it technically resembles valid syntax, but as the compiler pointed out, var is not a template).

The error you posted is actually a warning; it will not prevent your game from building nor harm its function. Interesting to note, though—I'm not sure why that function is being generated if ENIGMA is not using it. Probably a sloppy refactor.

How are you assigning to this global variable? How are you reading from it? This sounds as though there may be disparity, there. Are you declaring it global explicitly? If so, how?
Title: Re: Turning On A Variable Disables Character Movement
Post by: Hoohee on February 15, 2018, 11:04:37 pm
In the title screen of the game, I have an object containing this code in its "Create" event.

Code: [Select]
globalvar Vacuum;
Vacuum = 1;
globalvar Fuel;
Fuel = 1;;

Then in the level, following, there is another object made specifically for declaring these global variables again; except as 0.  I was told that it's better to declare global variables as 1 initially, but the way I made my game in GM, they were supposed to start at 0.
Title: Re: Turning On A Variable Disables Character Movement
Post by: Josh @ Dreamland on February 19, 2018, 01:55:47 pm
I can't think of any reason to favor declaring globals as one instead of zero. But "globalvar" is a GameMaker: Studio construct; ENIGMA just has you say "global var" instead. I can't tell if the compiler recognizes that you are trying to declare a global, or if it just assumes you left our two semicolons and wanted to say a bunch of variable names for no reason. The point is, it's possible globalvar just isn't working (although it seems to be declared in actions.h (https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Universal_System/actions.h#L285). Try printing the value in another object to make sure it's being persisted.

Otherwise, it could be an event ordering issue. Try setting it to what you mean instead of to one and then the correct value later.