Author Topic: Support_Prefs v3.1 - now with keybind  (Read 10721 times)

embedding this with Glass would be absolutely amazing.
Please make it happen.

i dont see anything wrong with it being standalone since i don't like bloating my blockland with a thousand addons bundled into one just cos i want to access prefs nicer

i have nothing against blockland glass although i don't even know what it is but i thought i should give my two cents!!
i dont even have two cents

i dont see anything wrong with it being standalone since i don't like bloating my blockland with a thousand addons bundled into one just cos i want to access prefs nicer

i have nothing against blockland glass although i don't even know what it is but i thought i should give my two cents!!
i dont even have two cents
i agree



if you want just make a duplicate of this add-on to be embedded into blockland glass

Well done. Just two things I'd like to note:

I'd recommend using Support_Preferences as a framework. It already has RTB and oRBs implementation and is meant to be a base for any and all preference clients to standardize communications and pref registration.

I'd also suggest looking in to using the pre-loader, so your add-on is guaranteed to load first and always load, whether it's enabled or not. Even though Mac and Windows load in reverse alphabetic order, running on Linux through wine seems to load add-ons in some other order, probably by date modified.

Well done. Just two things I'd like to note:

I'd recommend using Support_Preferences as a framework. It already has RTB and oRBs implementation and is meant to be a base for any and all preference clients to standardize communications and pref registration.

I'd also suggest looking in to using the pre-loader, so your add-on is guaranteed to load first and always load, whether it's enabled or not. Even though Mac and Windows load in reverse alphabetic order, running on Linux through wine seems to load add-ons in some other order, probably by date modified.
Ah.

This presents multiple problems for me.

Adding the preloader in is going to be fine as that's a simple change and I'll probably do it tommorow.

Integrating Support_Preferences, however, presents a slight (read: huge) issue because of the way my mod currently does things. I would have to rewrite everything and replace it with a system that can (from what I see here) do less than mine.

What I CAN do is add support for Support_Preferences.

Support for support.

...

Ephi, why did you loving leave.
« Last Edit: December 18, 2015, 04:08:22 PM by chrisbot6 »


Ah.

This presents multiple problems for me.

Adding the preloader in is going to be fine as that's a simple change and I'll probably do it tommorow.

Integrating Support_Preferences, however, presents a slight (read: huge) issue because of the way my mod currently does things. I would have to rewrite everything and replace it with a system that can (from what I see here) do less than mine.

What I CAN do is add support for Support_Preferences.

Support for support.

...

Ephi, why did you loving leave.
soooo can you list out what support_preferences can't do then?
considering we can add to it

soooo can you list out what support_preferences can't do then?
considering we can add to it
Yup. It was designed as an open standard after all.

Awesome! Downloading this.

soooo can you list out what support_preferences can't do then?
considering we can add to it
Yup. It was designed as an open standard after all.
Alright, considering you're double teaming me now...

Support_Prefs uses eval to get and set values. Not necessarily a problem if you're the trusting type, but not really something I like doing either because if someone runs this:
Code: [Select]
function BlocklandPrefSO::getValue(%this) {
return eval("return " @ %this.variable @ ";");
}
With the variable registered as something like
Code: [Select]
"crash()" // extreme example, I know"You're screwed. Eval is never a good idea. You use it in several other places too but at least there you add mild security by expanding your escape characters.

Take a look at "support/variables.cs" for my special method for getting around this. You'll find it interesting, I'm sure.

Also, there's the fact that Support_Prefs uses nonstandard seperator characters rather than torque's words and fields.
Code: [Select]
while(strLen(%params)) {
%pos = stripos(%params, "|");
%row = getSubStr(%params, 0, %pos);

%pref.rowName[%count] = getSubStr(%row, 0, stripos(%row, "**"));
%pref.rowValue[%count] = getSubStr(%row, stripos(%row, "**")+2, strLen(%row));
%pref.valueName[%pref.rowValue[%count]] = %pref.rowName[%count];

%count++;

if(stripos(%params, "|") != -1) {
%params = getSubStr(%params, stripos(%params, "|")+1, strLen(%params));
} else {
%params = "";
}
}
%pref.listCount = %count;
Which goes against my personal preference simply because a) there's no point and b) you're forcing a new format on everyone. Just use getWord/Words and getField/Fields, it would've been much easier for you to code and wouldn't cause this problem.

Keep in mind that sometimes list names will contain spaces. I have no doubt that this was your motive for doing it this way but there's really no point if the only word you need from each field is the first one. Or, do what I'm doing and extend the old RTB method (which JUST used words) by replacing underscores with spaces.
Code: [Select]
%optionCount = (getWordCount(%type) - 1) / 2;

for(%i = 0; %i < %optionCount; %i++) {
%first = (%i * 2) + 1;

%name = getWord(%type, %first);
%value = getWord(%type, %first+1);

%name = strreplace(%name, "_", " "); 

%input.add(%name, %value);
}
Because if you do it my way not only will old pref registrations work (lists limited to single word entries) but new ones will translate easily to the old system as well. I like the idea of this. Backwards compatibility is part of every good standard.

Code: [Select]
case "string" or "password":"password" doesn't need to be a default type. In fact, type is a bad place for declaring that certain prefs are private because now I can't add private values that are numbers or selection list. Think those won't be needed? Sure they'll be needed. What if I don't want to show everyone what AI mode a monster is set to? What if I don't want people to know what my lucky number is set to?

It needs its own value on the pref object.

Code: [Select]
case "slider":That's good. I don't have those yet.

Code: [Select]
function BlocklandPrefSO::findByVariable(%var) { // there's gotta be a better way to do thisThere is, if any of my guesses at what you're trying to do here are right.

If you're attaching variables to large tree structures instead of the prefs themselves (icons, for example) you should use global caches instead.

If the prefs are stored in the tree structure, use Badspot's NTObject optimization and list all their ids in a global array. My system uses "category" and "name" as a composite key for this since no two prefs can have the exact same category and name. Getting to them would be as simple as "$Pref[%cat @ "_" @ %name]" and checking they exist would be as simple as "$Pref[%cat @ "_" @ %name] !$= "" ".

$BLPrefs::Init should exist, because it's a standardized way of checking that a pref system is available.

-removed-

Code: [Select]
// the groups made things SO MUCH SIMPLER
for(%i=0;%i<%group.getCount();%i++) {
%row = %group.getObject(%i);
if($Pref::BLPrefs::ServerDebug) {
echo("\c4Sending" SPC %row.category @ "...");
}
commandToClient(%client, 'addCategory', %row.category, %row.icon);
}
Liking this. I only have two layers of iteration, but your prefs can go as deep as you want.
But do they really need to? What would a sub-sub-category even look like? Think about it.

Code: [Select]
// because oRBs is the same thing at this point -_-
// so much for "innovation", amirite?
Lol.
I never actually understood the point of renaming all of the oRBs functions. I assume it's so RTB won't have a naming conflict... with itself? I don't know.

That's pretty much it. If it's an open standard, fix some of this stuff. Copy paste some of my code if you like, I'm happy to help.
« Last Edit: December 18, 2015, 05:59:52 PM by chrisbot6 »

« Last Edit: December 18, 2015, 06:07:47 PM by Zeblote »

Oh, and there's this thing I just found that means I don't even have to name the mod ZZZZZZ any more:

So you don't need all of that code or standardization for simple preloading either. You can also do "always execute" stuff with that, if you're interested.
And how is this supposed to work in a dedicated server?

How do you want to activate this package before other add-ons start loading?
I completely forgot about the dedicated server situation and embarrassed myself, never mind that one.

I'll use the main.cs method instead.
« Last Edit: December 18, 2015, 06:04:24 PM by chrisbot6 »

Version 1.2
Code: [Select]
- Name is now Server_Prefs
- Fixed some bugs with names in list boxes
- Mod is now preloaded with a modified version of Greek2Me's preloader (fixed the very minor (see; completely insignificant) bug where nothing is "preloaded" on client's first run)
- Icons should now be loaded from Server_Prefs rather than ZZZZZZ_Prefs due to the name change.
- Presence checker variable is still $ZZZZZZ::Prefs.

Alright, considering you're double teaming me now...
because we designed it to be an RTB replacement that can be actively added onto. RTB should be dead.

Support_Prefs uses eval to get and set values. Not necessarily a problem if you're the trusting type, but not really something I like doing either because if someone runs this:
Code: [Select]
function BlocklandPrefSO::getValue(%this) {
return eval("return " @ %this.variable @ ";");
}
With the variable registered as something like
Code: [Select]
"crash()" // extreme example, I know"You're screwed. Eval is never a good idea. You use it in several other places too but at least there you add mild security by expanding your escape characters.
i don't quite get this community's hate towards eval. the way it's used here is perfectly fine, and it'd be the add-on developer's fault for putting it there in the first place.
by all means if you have a much better method, do tell, rather than trash eval.

Take a look at "support/variables.cs" for my special method for getting around this. You'll find it interesting, I'm sure.
Code: [Select]
function setGlobalByName(%global, %value) {
%firstLetter = getSubStr(%global, 0, 1);
%theRest = getSubStr(%global, 1, strLen(%global)-1);

if(%firstLetter $= "$") {
return setGlobalByName(%theRest, %value);
}

// IT CAN BE DONE WITHOUT EVAL GOD DAMN IT

switch$ (%firstLetter)
{
case "a":
$a[%theRest] = %value;
case "b":
$b[%theRest] = %value;
case "c":
$c[%theRest] = %value;
case "d":
$d[%theRest] = %value;
case "e":
$e[%theRest] = %value;
case "f":
$f[%theRest] = %value;
case "g":
$g[%theRest] = %value;
case "h":
$h[%theRest] = %value;
case "i":
$i[%theRest] = %value;
case "j":
$j[%theRest] = %value;
case "k":
$k[%theRest] = %value;
case "l":
$l[%theRest] = %value;
case "m":
$m[%theRest] = %value;
case "n":
$n[%theRest] = %value;
case "o":
$o[%theRest] = %value;
case "p":
$p[%theRest] = %value;
case "q":
$q[%theRest] = %value;
case "r":
$r[%theRest] = %value;
case "s":
$s[%theRest] = %value;
case "t":
$t[%theRest] = %value;
case "u":
$u[%theRest] = %value;
case "v":
$v[%theRest] = %value;
case "w":
$w[%theRest] = %value;
case "x":
$x[%theRest] = %value;
case "y":
$y[%theRest] = %value;
case "z":
$z[%theRest] = %value;
case "A":
$A[%theRest] = %value;
case "B":
$B[%theRest] = %value;
case "C":
$C[%theRest] = %value;
case "D":
$D[%theRest] = %value;
case "E":
$E[%theRest] = %value;
case "F":
$F[%theRest] = %value;
case "G":
$G[%theRest] = %value;
case "H":
$H[%theRest] = %value;
case "I":
$I[%theRest] = %value;
case "J":
$J[%theRest] = %value;
case "K":
$K[%theRest] = %value;
case "L":
$L[%theRest] = %value;
case "M":
$M[%theRest] = %value;
case "N":
$N[%theRest] = %value;
case "O":
$O[%theRest] = %value;
case "P":
$P[%theRest] = %value;
case "Q":
$Q[%theRest] = %value;
case "R":
$R[%theRest] = %value;
case "S":
$S[%theRest] = %value;
case "T":
$T[%theRest] = %value;
case "U":
$U[%theRest] = %value;
case "V":
$V[%theRest] = %value;
case "W":
$W[%theRest] = %value;
case "X":
$X[%theRest] = %value;
case "Y":
$Y[%theRest] = %value;
case "Z":
$Z[%theRest] = %value;
}
}
you're hoping the first character is a letter. what about numbers? what about underscores? periods? exclamation marks?

Also, there's the fact that Support_Prefs uses nonstandard seperator characters rather than torque's words and fields.
Code: [Select]
while(strLen(%params)) {
%pos = stripos(%params, "|");
%row = getSubStr(%params, 0, %pos);

%pref.rowName[%count] = getSubStr(%row, 0, stripos(%row, "**"));
%pref.rowValue[%count] = getSubStr(%row, stripos(%row, "**")+2, strLen(%row));
%pref.valueName[%pref.rowValue[%count]] = %pref.rowName[%count];

%count++;

if(stripos(%params, "|") != -1) {
%params = getSubStr(%params, stripos(%params, "|")+1, strLen(%params));
} else {
%params = "";
}
}
%pref.listCount = %count;
Which goes against my personal preference simply because a) there's no point and b) you're forcing a new format on everyone. Just use getWord/Words and getField/Fields, it would've been much easier for you to code and wouldn't cause this problem.

Keep in mind that sometimes list names will contain spaces. I have no doubt that this was your motive for doing it this way but there's really no point if the only word you need from each field is the first one. Or, do what I'm doing and extend the old RTB method (which JUST used words) by replacing underscores with spaces.
i did it this way in case a newer addon developer didn't understand fields/tabs. i'd figure too it'd stand out easier and be much easier to look over and understand. tabs can look like spaces and this can throw off someone looking at another addon using the system for reference.
not everyone here is a super-duper highly-skilled developer.
do bare in mind though that nothing is preventing you from also adding that as an alternate method to the prefs system. it's open source for a reason.

it's rather not use underscores in case those are needed.

Code: [Select]
%optionCount = (getWordCount(%type) - 1) / 2;

for(%i = 0; %i < %optionCount; %i++) {
%first = (%i * 2) + 1;

%name = getWord(%type, %first);
%value = getWord(%type, %first+1);

%name = strreplace(%name, "_", " "); 

%input.add(%name, %value);
}
Because if you do it my way not only will old pref registrations work (lists limited to single word entries) but new ones will translate easily to the old system as well. I like the idea of this. Backwards compatibility is part of every good standard.
https://github.com/TheBlackParrot/blockland-preferences/blob/master/compatibility.cs

Code: [Select]
case "string" or "password":"password" doesn't need to be a default type. In fact, type is a bad place for declaring that certain prefs are private because now I can't add private values that are numbers or selection list. Think those won't be needed? Sure they'll be needed. What if I don't want to show everyone what AI mode a monster is set to? What if I don't want people to know what my lucky number is set to?
Code: [Select]
==>echo("1" + 1);
2
reminder this is torque and a string can act as a number if the string is numeric.

we're not sure how exactly to implement something like that for lists, we could add an argument to limit visibility of the pref based on rank.

Code: [Select]
function BlocklandPrefSO::findByVariable(%var) { // there's gotta be a better way to do thisThere is, if any of my guesses at what you're trying to do here are right.

If you're attaching variables to large tree structures instead of the prefs themselves (icons, for example) you should use global caches instead.

If the prefs are stored in the tree structure, use Badspot's NTObject optimization and list all their ids in a global array. My system uses "category" and "name" as a composite key for this since no two prefs can have the exact same category and name. Getting to them would be as simple as "$Pref[%cat @ "_" @ %name]" and checking they exist would be as simple as "$Pref[%cat @ "_" @ %name] !$= "" ".

$BLPrefs::Init should exist, because it's a standardized way of checking that a pref system is available.
then revise it lol
we're open source for a reason

Code: [Select]
// the groups made things SO MUCH SIMPLER
for(%i=0;%i<%group.getCount();%i++) {
%row = %group.getObject(%i);
if($Pref::BLPrefs::ServerDebug) {
echo("\c4Sending" SPC %row.category @ "...");
}
commandToClient(%client, 'addCategory', %row.category, %row.icon);
}
Liking this. I only have two layers of iteration, but your prefs can go as deep as you want.
But do they really need to? What would a sub-sub-category even look like? Think about it.
this is something clients should handle, i think of it like a wiki entry.

Code: [Select]
// because oRBs is the same thing at this point -_-
// so much for "innovation", amirite?
Lol.
I never actually understood the point of renaming all of the oRBs functions. I assume it's so RTB won't have a naming conflict... with itself? I don't know.
orbs is RTB with forced registrations from the outside, broken IRC, and with all the previous issues that remain to be fixed
plus tenshi. i wouldn't trust tenshi with a toothpick.

That's pretty much it. If it's an open standard, fix some of this stuff. Copy paste some of my code if you like, I'm happy to help.
then hellllppppp.