Dvar Struct Toggles

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
Caution:
The scripts below are untested.


I thought about making dvar toggles easier and this is what I got. Structs are very underrated and should be used more since they are very useful in reducing redundancy in the code. As you can see, there is zero redundancy now so the code is clean:
Code:
toggleSuperMeleeRange()
{
    if(!isDefined(level.superMeleeRange))
    {
        level.superMeleeRange = createDvarStructure("player_meleeRange", 9999, 1);
    }
   
    self toggleDvarStructure("Super Melee Range", level.superMeleeRange, true);
}

Code:
createDvarStructure(name, enabled, disabled)
{
    structure                        = spawnStruct();
    structure.name                    = name;
    structure.enabled                = enabled;
    structure.disabled                = disabled;
    structure.state                 = getDvarInt(name) == enabled;
  
    level thread disableDvarStructureWhenGameEnded(structure);

    return structure;
}

disableDvarStructureWhenGameEnded(structure)
{
    level waitTill("game_ended");
    setDvar(structure.name, structure.disabled);
}

toggleDvarStructure(modName, structure, printGlobally)
{
    structure.state = self invertAndPrint(modName, structure.state, printGlobally);
    setDvarStructureValue(structure);
}

setDvarStructureValue(structure)
{
    value = structure.state ? structure.enabled : structure.disabled;
    setDvar(structure.name, value);
}
This also automatically turns off the dvar but is not necessary for this to work properly since the starting boolean state is always determined according to the actual dvar value and not some predetermined true or false which could be wrong.

Note:
You can grab the invertAndPrint() function here.
 
Last edited:

The Dark Side

Former Staff Member
Messages
1,012
Reaction score
785
Points
993
Caution:
The scripts below are untested.


I thought about making dvar toggles easier and this is what I got. Structs are very underrated and should be used more since they are very useful in reducing redundancy in the code. As you can see, there is zero redundancy now so the code is clean:
Code:
toggleSuperMeleeRange()
{
    level.superMeleeRange = createDvarStructure("player_meleeRange", 9999, 1);
    self toggleDvarStructure("Super Melee Range", level.superMeleeRange, true);
}

disableSuperMeleeRange()
{
    disableDvarStructure(level.superMeleeRange);
}

Code:
createDvarStructure(name, enabled, disabled)
{
    structure                        = spawnStruct();
    structure.name                    = name;
    structure.enabled                = enabled;
    structure.disabled                = disabled;
    structure.state                 = getDvarInt(name) == enabled;

    return structure;
}

toggleDvarStructure(modName, structure, printGlobally)
{
    structure.state = self invertAndPrint(modName, structure.state, printGlobally);
    setDvarStructure(structure);
}

setDvarStructure(structure)
{
    value = structure.state ? structure.enabled : structure.disabled;
    setDvar(structure.name, value);
}

disableDvarStructure(structure)
{
    if(isDefined(structure))
    {
        setDvar(structure.name, structure.disabled);
    }
}
disableDvarStructure() should be used when the game ends to turn off the dvar if desired but is not necessary for this to work properly since the starting boolean state is always determined according to the actual dvar value and not some predetermined true or false which could be wrong.

Note:
You can grab the invertAndPrint() function here.
Ill try this out! Well done!
 
S

SeriousHD-

Guest
Caution:
The scripts below are untested.


I thought about making dvar toggles easier and this is what I got. Structs are very underrated and should be used more since they are very useful in reducing redundancy in the code. As you can see, there is zero redundancy now so the code is clean:
Code:
toggleSuperMeleeRange()
{
    level.superMeleeRange = createDvarStructure("player_meleeRange", 9999, 1);
    self toggleDvarStructure("Super Melee Range", level.superMeleeRange, true);
}

disableSuperMeleeRange()
{
    disableDvarStructure(level.superMeleeRange);
}

Code:
createDvarStructure(name, enabled, disabled)
{
    structure                        = spawnStruct();
    structure.name                    = name;
    structure.enabled                = enabled;
    structure.disabled                = disabled;
    structure.state                 = getDvarInt(name) == enabled;

    return structure;
}

toggleDvarStructure(modName, structure, printGlobally)
{
    structure.state = self invertAndPrint(modName, structure.state, printGlobally);
    setDvarStructure(structure);
}

setDvarStructure(structure)
{
    value = structure.state ? structure.enabled : structure.disabled;
    setDvar(structure.name, value);
}

disableDvarStructure(structure)
{
    if(isDefined(structure))
    {
        setDvar(structure.name, structure.disabled);
    }
}
disableDvarStructure() should be used when the game ends to turn off the dvar if desired but is not necessary for this to work properly since the starting boolean state is always determined according to the actual dvar value and not some predetermined true or false which could be wrong.

Note:
You can grab the invertAndPrint() function here.
Bro why.... This is so redundant its not even funny lol
 
S

SeriousHD-

Guest
It's not, I'll use to eliminate dvar bugs and redundancy :smirk:
First problem: Struct. Why use a struct with several vars and define several variables when you could toggle with a ternary operator?
Second problem: 4 functions for 1 dvar. Hmmm..
3rd problem: Everything
 

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
First problem: Struct. Why use a struct with several vars and define several variables when you could toggle with a ternary operator?
Second problem: 4 functions for 1 dvar. Hmmm..
3rd problem: Everything
1) How do you know the starting value? This is also to not repeat yourself when you also need to toggle it off when the game ends. You can't do that with a ternary since you have to mention the "off value" again
2) This is meant to be used for many dvar toggles. I just used one as an example so it will pay off with 5 or 10+ of them like usually the case in most big menus
3) I guess there is no need to comment on that. Space is not sparse so you can use a few more lines to improve the coding :sweatsmile:
 
Last edited:
S

SeriousHD-

Guest
1) How do you know the starting value? This is also to not repeat yourself when you also need to toggle it off when the game ends. You can't do that with a ternary since you have to mention the "off value" again
2) This is meant to be used for many dvar toggles. I just used one as an example so it will pay off with 5 or 10+ of them like usually the case in most big menus
3) I guess there is no need to comment on that. Space is not sparse so you can use a few more lines to improve the coding :sweatsmile:
Well, lets see then.

level.Whateverthefuck = getDvar("whateverthefuck") == "somethingidgaf";

Then,
SetDvar( "whateverthefuck", (level.whateverthefuck = !level.whateverthefuck) ? "something : "else" );
 

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
Well, lets see then.

level.Whateverthefuck = getDvar("whateverthefuck") == "somethingidgaf";

Then,
SetDvar( "whateverthefuck", (level.whateverthefuck = !level.whateverthefuck) ? "something : "else" );
No.
  • You're repeating the dvar name String
  • You're not including any printing (it's also not supported to include in ternaries)
  • Disabling would repeat the dvar name String and disable value which is generally needed when the game ends
Face it, my solution is clean but a few lines longer than others. It pays off when used often.
 
S

SeriousHD-

Guest
No.
  • You're repeating the dvar name String
  • You're not including any printing (it's also not supported to include in ternaries)
  • Disabling would repeat the dvar name String and disable value which is generally needed when the game ends
Face it, my solution is clean but a few lines longer than others. It pays off when used often.
Its doesnt lmao, and ternary are supported lmao. Who cares if you repeat the string? You are literally making no sense right now. You sound like one of the AP Comp sci kids first learning java.
 

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
Its doesnt lmao, and ternary are supported lmao. Who cares if you repeat the string? You are literally making no sense right now. You sound like one of the AP Comp sci kids first learning java.
It's called
You do not have permission to view link Log in or register now.
but if you don't care or have no clue about software engineering, that's fine. Apparently everybody else agrees with me though :wink:
 
Last edited:
S

SeriousHD-

Guest
It's called
You do not have permission to view link Log in or register now.
but if you don't care or have no clue about software engineering, that's fine. Apparently everybody else agrees with me though :wink:
Really bud? No ****. But, apparently you are forgetting the fact that you also need to look for overall efficiency and effectiveness and make a compromise between the 3. When a function like setdvar is built into the game as a variable storage system which takes at most 2 strings, and you decide to make a struct with 5 variables to handle it, you completely **** on the efficiency side of it. Secondly, effectively speaking, this is ridiculous as well because you are requiring a specific structure to be handled every time you need to call a method which was built to handle exactly that. You cant learn everything about this stuff in school bud, a lot is from general practice too. You should be able to know when a piece of methodology is redundant enough to be considered non applicable to textbook style.

And as far as "everyone else", they are just being nice because either they do not understand this principle or they are trying to be supportive. Overall, this is entirely useless and in a real world scenario: detrimental. Script variables take memory too. Dont forget we are talking about an actual runtime environment here, and your "pretty code" isnt going to matter when the script is forced to break runtime from lack of space in memory. Stop acting like your google searches mean something and realize you are wrong.
 

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
Script variables take memory too. Dont forget we are talking about an actual runtime environment here, and your "pretty code" isnt going to matter when the script is forced to break runtime from lack of space in memory. Stop acting like your google searches mean something and realize you are wrong.
Memory problems you say? Hmm, I guess nobody has ever hit any limits though but let's see about the "memory waste" I'm causing:
10 * ((8 * 3) + 4 + 4 + 4) = 360 byte

How much RAM is available?

PS3 RAM (256 MB * 2):
You do not have permission to view link Log in or register now.


Wii U RAM (1 GB):
You do not have permission to view link Log in or register now.


PC RAM (varying but multiple GBs)

Of course the GSC script memory might be much less so let's say it's 1/10 of the available RAM of the PS3:
256MB / 10 = 25MB = 26214400 B

Memory occupied ratio:
360 / 26214400 = 0.00001373291015625 = 0.001373291015625%

So yeah, nice theory bro.
Secondly, effectively speaking, this is ridiculous as well because you are requiring a specific structure to be handled every time you need to call a method which was built to handle exactly that.
Efficiency? You think using a simple struct to access data is going to impact performance when a menu function is clicked on once in awhile? Come on. Do I need to write down calculations here as well or are you going to give in? :tearsofjoy:

Stop acting like your google searches mean something and realize you are wrong.
What about you realize that you're wrong? You aren't some kind of expert here so stop thinking your views are irrefutable when you haven't supplied a single proper argument so far :tearsofjoy:
 
Last edited:
S

SeriousHD-

Guest
What about you realize that you're wrong?

Memory problems you say? Hmm, I guess nobody has ever hit any limits though. Also this is only called a few times and not a million times.

Let's see about the memory waste I'm causing:
10 * ((8 * 3) + 4 + 4 + 4) = 360 byte

How much RAM is available?

PS3 RAM (256 MB * 2):
You do not have permission to view link Log in or register now.


Wii U RAM (1 GB):
You do not have permission to view link Log in or register now.


PC RAM (varying but multiple GBs)

Of course the GSC script memory might be much less so let's say it's 1/10 of the available RAM of the PS3:
256MB / 10 = 25MB = 26214400 B

Memory occupied ratio:
360 / 26214400 = 0.00001373291015625 = 0.001373291015625 %

Nice story bro. :tearsofjoy:
Thats not what im talking about. You know that error you get halfway through your game where it kicks you out saying you have too many script variables? That is extremely small compared to actual memory. And you are acting as though the memory space in the console is 100% empty. Ever taken a dive through there? Every single thing the game uses in piled into ram, including your script variables, which by the way, you are limited to around 900 or so before the console crashes. So in reality, lets do the math: 5/900 = .5%. Then we are going to say we want to use 10 to 20 dvars ( verification and other matters ) so 50 to 100 (aka 5% to 11%) which in reality, is a **** ton.

Relative to :
1 level variable and 1 string reference.
20 to 40, (2.2% to 4.4%).

Hmmmmm....
You are wrong yet again.
 

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
Every single thing the game uses in piled into ram, including your script variables, which by the way, you are limited to around 900 or so before the console crashes.
Lmfao, says who? :tearsofjoy:

So you're saying that a variable in a struct is the same as an own level variable and I can therefore only hold 900-ish values in total?

Let's say you're right. Then I should be able to write a test code which adds elements to a level array (random integers) and it would crash around the mentioned amount.

I tried it out and guess how far it got? At 10000 array elements it's still running just fine so your puny argument about memory space is invalid. Next time cut back a little bit with the trolling if you don't know your stuff, won't you? You've just been proven wrong so what's your next claim? :tearsofjoy:

Code:
init()
{
    level thread onPlayerConnect();
}

onPlayerConnect()
{
    while(true)
    {
        level waittill("connected", player);
        player thread onPlayerSpawned();
    }
}

onPlayerSpawned()
{
    self endon("disconnect");
    level endon("game_ended");

    while(true)
    {
        self waitTill("spawned_player");
   
        if(!isDefined(level.memoryTesting))
        {
            self thread testMemory();
        }
    }
}

testMemory()
{
    level.memoryTesting = [];

    while(true)
    {
        randomInteger = randomIntRange(70000, 2000000000); // Force random integer
        level.memoryTesting[level.memoryTesting.size] = randomInteger; // Add the new variable
        self iPrintln("Size: " + level.memoryTesting.size); // Print the total array size

        wait 0.05;
    }
}
 
S

SeriousHD-

Guest
Lmfao. :tearsofjoy:

So you're saying that a variable in a struct is the same as an own level variable and I can therefore only define 900-ish variables in total?

Let's say you're right. Then I should be able to write a test code which adds elements to a level array (random integers) and it would crash around the mentioned amount.

I tried it out and guess how far it got? At 10000 array elements it's still running just fine so your puny argument about memory space is invalid. Next time cut back a little bit with the trolling if you don't know your stuff, won't you? Will you finally give up? :tearsofjoy:

Code:
init()
{
    level thread onPlayerConnect();
}

onPlayerConnect()
{
    while(true)
    {
        level waittill("connected", player);
        player thread onPlayerSpawned();
    }
}

onPlayerSpawned()
{
    self endon("disconnect");
    level endon("game_ended");

    while(true)
    {
        self waitTill("spawned_player");
    
        if(!isDefined(level.memoryTesting))
        {
            self thread testMemory();
        }
    }
}

testMemory()
{
    level.memoryTesting = [];

    while(true)
    {
        randomInteger = randomIntRange(70000, 2000000000); // Force random integer
        level.memoryTesting[level.memoryTesting.size] = randomInteger; // Add the new variable
        self iPrintln("Size: " + level.memoryTesting.size); // Print the total array size

        wait 0.05;
    }
}
Seriously... Are you paying attention to what im saying or are you too busy bullshiting? GSC does not handle memory the same way C does. It is a game engine, meaning it has its own ruleset. Arrays have memory blocks like lists do. GSC Limits unique identifiers. structs included.
If you did the same thing with new structs it would crash.
 

BullyWiiPlaza

Modder
Messages
215
Reaction score
174
Points
818
If you did the same thing with new structs it would crash.
You're so desperately trying to be right but sorry to disappoint you. With
Code:
spawnStruct()
it's the same thing. I'm in the 1000's and nothing. GG mate, you lose. Now what? Admit defeat or invent more random bullshit? :sweatsmile:
Code:
testMemory()
{
    level.memoryTesting = [];

    while(true)
    {

        struct = spawnStruct();
        struct.name = "Anthony";
        struct.num = randomIntRange(70000, 2000000000);
        struct.val = (50, 10, 9);

        level.memoryTesting[level.memoryTesting.size] = struct; // Add the new struct
        self iPrintln("Size: " + level.memoryTesting.size); // Print the total array size

        wait 0.05;
    }
}
 
S

SeriousHD-

Guest
You're so desperately trying to be right but sorry to disappoint you. With
Code:
spawnStruct()
it's the same thing. I'm in the 1000's and nothing. GG mate, you lose :sweatsmile:
Code:
testMemory()
{
    level.memoryTesting = [];

    while(true)
    {
 
        struct = spawnStruct(); // Force random integer
        struct.name = "Anthony";
        struct.num = randomIntRange(70000, 2000000000);
        struct.val = (50, 10, 9);

        level.memoryTesting[level.memoryTesting.size] = struct; // Add the new variable
        self iPrintln("Size: " + level.memoryTesting.size); // Print the total array size

        wait 0.05;
    }
}
Well then i dont know the script variable limit, but thats besides the point. We were arguing about singularity efficiency and in that case im still right. In the end, its the point that you dont need to code more to do less. This is a key principle in real world code application. Im done with this argument because it is consistently putting a damper on my mood at this point and if i cant convince you in a few posts than you will have to find out yourself.
 
Top