How do I change a local number in a different group?

0 favourites
  • 10 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • EDIT: THE ISSUE IN THIS POST HAS BEEN SOLVED. SEE A COUPLE POSTS DOWN FOR THE NEW ONE I'M HAVING. (didn't want to make a whole new thread)

    I'm making a game where you can upgrade the various statistics of your weapons, and to organize it better and make things work consistently I have organized the weapons' stats and firing patterns into groups:

    (ignore the names and stuff, this is just from my early dev file)

    Inside each group are a bunch of variables that pertain to the stats of each weapon as well as the math that determines what they do:

    (the player will be able to upgrade or change each of these numbers)

    If I place a button inside the group I can change the number, but all of my upgrade buttons and my pause menu are in a separate group because they have to be in order to be usable. So, is it possible to change a global number that is inside a different group, or will I have to do some reorganizing? If it isn't possible, how would you recommend I go about fixing/reorganizing it?

  • Global variables are not linked to a specific group, in that case they will turn into local variables, and are only available to that group.

    I don't think there are any logical or good way to do it. Due to several reason, it would be very inconvenient to work with variables that way, and it will complicate things for you unnecessarily.

    Want i would suggest and a way that i personally think is a good way to organise things, as im not a huge fan of global variables in general, as you tend to end up with a very long list and after a while its very hard to maintain an overview of what variables does what and where they are used, so i use them only for very few things. Instead i would suggest you to make a small sprite or a series of them, what you prefer and depending on how many weapons you have, but just a size of 16x16 and place it outside the layout and you use this/these for storing your weapon settings.

    So if you give it a name like "Weapon settings" whenever you need to get a value or setting for a weapon you know that these are found in that sprite. And you don't have to worry about loosing control of them, as these are only used for weapons. So when you look through your "Add action/Add event" things will be a lot more organized. And if you ever need to change any settings you can just update the values in that sprite.

    I normally use several of these types of sprites, for "Names", "Weapons", "System settings", "Enemy settings" etc. and since they are so small in size they will have near to no impact on performance and they allow you to use Booleans. And if you need them to be global you just set the sprite global value to true.

    However just be sure that whenever you need a value that you get it from the sprite, and not just make a "Set weapon damage = 2" etc as that would give you wrong data at some point. However that also means that its very easy to update your whole project in one go, if you decide at some point that a certain weapon should do more damage.

  • Ahh, that does seem like a clever way of doing things. I'll try that. Thank you for the quick reply!

  • Update: Now that I've made the changeover and re-written the code, other things have broken! Previously the shotgun fired straight out of the barrel at the angle I set:

    (old code method)

    But now when I fire, this happens:

    (new code method)

    I can't tell at a glance what has changed or what I did wrong in the crossover, so I'll post both the new and old shotgun fire code and let people more experienced than me take a look at it (you'll probably have to open them in a new tab to view them in full, they're big and I don't have enough posts to use URLs yet).

    (old code, note the variables being part of the group)

    (new code, variables are a part of a sprite called 'codebox_shotgun_stats')

  • Based on post from nimos, I assumed you implemented it, LocalVariable always reset to it's default value, while StaticVariable does not, so you need to reset those variable in the For loop action to make it behave similarly to your old version.

  • If you made more than one "codebox_shotgun_stats" you need to pick the correct one first. Note, you don't need the "Group is active" test as that code can only be reach IF the group is active!

  • Based on post from nimos, I assumed you implemented it, LocalVariable always reset to it's default value, while StaticVariable does not, so you need to reset those variable in the For loop action to make it behave similarly to your old version.

    This does sound like it would work, but I'm not sure I understand what I need to do to reset the variable to what it was before and still have the gun be upgrade-able. If you could go a bit more in-depth I'd appreciate it.

    If you made more than one "codebox_shotgun_stats" you need to pick the correct one first. Note, you don't need the "Group is active" test as that code can only be reach IF the group is active!

    Thanks for the tip, redundancy removed!

  • After doing some bug testing it appears that a_shotgun_x is the culprit. When this line is enabled in the code:

    the shotgun does the angle thing it was doing above because:

    a_shotgun_x does not reset to 0. If I set it to reset to 0 in the action where the gun fires, it will only shoot 1 pellet for god knows what reason. I've officially given up on trying to explain why this is in words so here, I'll just upload my dev .capx and let you guys play around with it if anyone's interested in finding out what's wrong and/or want to explain how to fix it.

    After doing some bug testing it appears that a_shotgun_x is the culprit. When this line is enabled in the code:

    the shotgun does the angle thing it was doing above because:

    a_shotgun_x does not reset to 0. If I set it to reset to 0 in the action where the gun fires, it will only shoot 1 pellet for god knows what reason. I've officially given up on trying to explain why this is in words so here, I'll just upload my dev .capx and let you guys play around with it if anyone's interested in finding out what's wrong and/or want to explain how to fix it.

  • Line32, set a_shotgun_1 to 0.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Haha, wow, don't I feel stupid. I was putting it in the wrong place. Thanks a bunch!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)