How do I count usages of my variables? (in the Global Variables dialogue)

Started by bx83, Tue 27/07/2021 11:24:50

Previous topic - Next topic

bx83

I have a huge number of variables in Global Variables (like >500), and I was wondering if there was a way to check:
-if any had 0 or 1 only usages (in which case, I can delete or repurpose them)
-if you can count the number of variables?

Thanks!

Cassiebsg

As far as I know you can't, but I might be wrong.
You can however right click one in script and check all usage of it. But it's a one by one process, so probably only useful if you suspect it to be a 0 or 1 only usage....
There are those who believe that life here began out there...

bx83


Crimson Wizard

Well, you can -

1. Right click on a variable in the Global Variables table -> Find all usages.

2. Do "Edit"->"Find" (Ctrl+F), set "Look In" option to "Current Project", type in variable name and search.

3. Use a file explorer to search for the variable name in the project folder.
Windows Explorer is horrible for tasks like this (at least in versions where I tried), personally I like "FAR Manager", but it's a matter of preference.

It's true that you will have to do this for each individual variable, one by one. So it may be 500+ right clicks and "Find all usages".

fernewelten

Quote from: bx83 on Tue 27/07/2021 14:30:12
...How do I request a feature from the developers?

Here.
You'll need a Github account which is free.

newwaveburritos

I recently cleaned house on the global variables since mine were also getting a little out of control.  I found quite a few I had written before I really understood what I was doing and could be deleted or changed to what I guess you would call "room variables" in order to keep the list a little tidier.  It was a bit arduous but I felt good about it afterward even though the list is still kind of a mess.  I've also learned that inventory items and regions turning on and off and Game.DoOnlyOnce can act as variables for a lot of the things I was tracking in the game.  But I am also not really doing a lot of advanced work.  I'm sure I'll read this again in six months and think of myself as a sweet summer child.  I'm not sure if this is really helpful or not but maybe a little.  For what it's worth you can also count the variables you can see in the window and notice where it falls when scrolling all the way down and do a little math.  I can see 26 at a time so if I have four "screens" there's about 100.

Khris

Just for reference, global variables are easier to maintain in scripts. It works like this:

Code: ags
// header
import Character *sidekick; // same as declaration, with import at the start
import int muffins_eaten;  // no value though, just type and name

// global script
Character *sidekick;
int muffins_eaten = 1; // initial value allowed for primitive types (bool, float, int)
export sidekick, muffins_eaten; // just the name, so you can list different types here


In addition you can group them by using structs:
Code: ags
// header
struct ChapterOne {
  bool body_found;
  bool asked_about_freddy;
};

import ChapterOne c1;

// main script
ChapterOne c1; export c1;


Now you can type  c1.  anywhere and a list of your struct's globals pops up.


Crimson Wizard

QuoteA button in 'edit variable' which lists scripts and functions in which a variable is used.

Like I mentioned earlier, such command already exists.

bx83

You did, but not one that checks all variables at once.
I’ll get rid off the one in the feature request.

SMF spam blocked by CleanTalk