usefulscript

Started by matt, Thu 30/10/2008 09:41:57

Previous topic - Next topic

matt

i made this really basic but very use ful script in the editor. put it at the very top of the script you want to use it in and then just type allguis(true) or allguis(false).

function allguis (bool visible) {
  int guis = Game.GUICount;
  int cgui = 0;
  while (cgui <= guis) {
    gui[cgui].Visible = visible;
    cgui++;
  }
}

what?

Ghost

#1
Amazing! I shall go and use it all of the time now! Thanks a lot!

[edit]
And very sensible to put it here, instead of the TECHNICAL FORUM or MODULES- I mean, this snippet is surely worth a discussion!

R4L

You know this isn't the right place for this right?

monkey0506

"usefulscript" must clearly be some type of new word you're trying to invent indicating, "a small, abiguous, and majorly useless code snippet posted in an irrelevant place." My question to you is, do you have a license for that? You may not be aware, but only those officially sanctioned and licensed members have the right to make up words at will or on a whim.

This function you've written, in addition to being posted in the wrong forum does have other fundamental flaws:

1) It is completely ambiguous! The name of the function gives no indication what the function does. "allguis" does indicate all GUIs, but what am I doing with them? Am I checking the number of them? Checking if they're all turned on? Checking this property or that? Setting the other? The name of the function says nothing as to what you are doing with all GUIs.

2) It's very much a specialized function. Definitely a lot of games would have a situation where they would want to have all their GUIs turned off. Very few games have a situation where they would want or need every GUI turned on at the same time!

A better* alternative to this function would be something like this:

Code: ags
// script header
import void TurnGUIsOff();
import void RestoreGUIsVisibility();

// script
bool GUIPrevVisible[];

function game_start() {
  GUIPrevVisible = new bool[Game.GUICount];
  int i = 0;
  while (i < Game.GUICount) {
    GUIPrevVisible[i] = gui[i].Visible;
    i++;
  }
}

void TurnGUIsOff() {
  int i = 0;
  while (i < Game.GUICount) {
    GUIPrevVisible[i] = gui[i].Visible;
    gui[i].Visible = false;
    i++;
  }
}

void RestoreGUIsVisibility() {
  int i = 0;
  while (i < Game.GUICount) {
    gui[i].Visible = GUIPrevVisible[i];
    i++;
  }
}


*"better" is completely a partial and biased term. Some users may disagree that the above is "better" than the original posted code snippet, but in this user's opinion it provides better and less specialized functionality.

Trent R

I have three points to make:

1. You script is pointless. Why would I want all my GUIs on at once?

2. Your script is broken. int guis returns a count of your GUIs, but then your while loop says it's out of bounds. You need
Code: ags
  while (cgui < guis) { //remove the <=
or even
Code: ags
  while (cgui <= guis-1) { //insert -1


3. Nonetheless, I don't want to be completely negative, so I decided to try it out (the fixed version of point two). This was my result:

Wait a second, point 3 just reinforces point 1.
Forgive me, I only have two points to make.

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

jetxl

O-oh, here comes the snob patrol.

Hammerite

Perhaps it was a prank?
i used to be indeceisive but now im not so sure!

monkey0506

Quote from: jetxl on Sat 01/11/2008 09:26:36O-oh, here comes the snob patrol.

Just FYI despite how the tone of my post may have been perceived, I wasn't trying to be snobbish (well at least not so much toward the end of the post as the beginning :=). I told him two valid reasons why the code isn't really as useful as the name of the thread suggests, and even posted a "better" alternative for those reading it (as well as the author).

In addition to my original two points, Trent's 2nd is absolutely correct in that the wrong operator is used, effectively breaking the script as well (run-time crash anytime the function is called).

I actually doubt it was intent as some type of Halloween prank, but whether it was or not, the three points (my original two plus Trent's second) that have been made regarding the script are still valid. As is Ghost's point about it being in the wrong forum.

SMF spam blocked by CleanTalk