Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Tue 27/07/2021 11:24:50

Title: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: bx83 on Tue 27/07/2021 11:24:50
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!
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: Cassiebsg on Tue 27/07/2021 12:13:27
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....
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: bx83 on Tue 27/07/2021 14:30:12
...How do I request a feature from the developers?
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: Crimson Wizard on Tue 27/07/2021 16:10:23
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".
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: fernewelten on Tue 27/07/2021 16:47:25
Quote from: bx83 on Tue 27/07/2021 14:30:12
...How do I request a feature from the developers?

Here (https://github.com/adventuregamestudio/ags/issues/new?labels=emplate=feature_request.md).
You'll need a Github account which is free.
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: newwaveburritos on Tue 27/07/2021 19:20:04
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.
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: Khris on Tue 27/07/2021 20:28:21
Just for reference, global variables are easier to maintain in scripts. It works like this:

Code (ags) Select
// 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) Select
// 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.
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: bx83 on Wed 28/07/2021 00:12:45
https://github.com/adventuregamestudio/ags/issues/1374
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: Crimson Wizard on Wed 28/07/2021 00:54:13
QuoteA button in 'edit variable' which lists scripts and functions in which a variable is used.

Like I mentioned earlier, such command already exists.
Title: Re: How do I count usages of my variables? (in the Global Variables dialogue)
Post by: bx83 on Wed 28/07/2021 03:10:04
You did, but not one that checks all variables at once.
I’ll get rid off the one in the feature request.