« first day (2431 days earlier)      last day (2549 days later) » 
00:00 - 20:0020:00 - 00:00

8:00 PM
I have a plan for this to work in the end, but none for the simplified version.
 
you already have the bonus type saved on the bonus somehow?
like
dodge_feat = { 1, 'dodge' }
full_plate_mail = { 9, 'armor' }
mage_armor = { 4, 'armor' }
If you do, you can write a second array that only stores the value of each bonus that have the same name, then loop through this array looking for the highest integer, like this:
var array = [4 , 9, 1];
var highest= 0;
for (i=0; i<=highest;i++)
if (array[i]>highest)
var highest=array[i];
 
8:16 PM
@ShadowKras right now it is an object with several ...mh, how are they called... several couples of values and label and one label is "value"
mh, so you suggest manually writing arrays rather than having the bonus name as part of the object.
 
no, you can do that by writing a function with the parameters bonus name and the object that contains the bonuses and their value, which returns the highest that got that name.
example: var armorBonus = highestBonus('armor'', { 1, 9, 4, 2 });
that array could already have the desired bonus type (by writing manually), or that could be done inside the function, but it will be a little slower
 
So let's say I write the armorBonus function like you suggested, as it is now it is a list of numbers. And some of those numbers are tied to one checkbox, some to the other. I oly want the function to look at the numbers tied to the object with the ticked box.
I'm thinking about multiplying each number by the truty or falsy value of the checkbox, by hand for now.
 
you have the bonus type written down somewhere, right?
you can loop through the objects checking for a property with a name you created (ie: bonustype) and obtain their value property, and save the values into the array.
you know you can make up html properties right?
if the value is stored in an object, writing a function to search through the properties of that object is simple, like this
 
buff [{
    "name":"mage armor"
    "type":"armor"
    "value":4
},...
 
if the value is stored in a html property (inside an input, or div for example) you can use the getAttributes function.
your object is exactly like the one on the example of the first link.
 
8:28 PM
I've never encountered reduce before, let's see what it does...
 
buff['type'] will return the value of type.
and buff['value'] will return the value of value.
 
and then how do I get the name of the object with the highest type?
 
your need the name or it's value?
 
(The more I progress, the more this looks complicated to me. And here I tought I was a smart guy)
 
buff['name'] returns the name.
 
8:32 PM
@ShadowKras I need both, for I need to output a string that's " +" + value + " (" + name + ")"
 
you have several buff objects, right?
save them all inside an array.
 
right now it's a single buff array containing several objects
 
write a function that has two arguments, the type and this array, and it will loop through your array of buffs looking for the buff object with the highest value.
 
find the index of the highest value, apply same index to find the right name, right
I have something like that on my woirkplace's PC
 
that's the best solution, yes. Remember what we were talking about indexing the other day?
 
8:34 PM
and of course I can't access it now
I already have that function ready and tested
I did it during lunchtime at work
 
cool, then you simply need to create a function to loop inside the array looking for the highest value
 
but I'm not allowed to use USB keys there
I think I will do the strings by hand for tomorrow's game
 
save it online
 
@ShadowKras I don't think the IT manager would let me
I didn't ask, because I want to lead a peaceful life.
 
okay, here is what you want to do:
first write a loop that goes through your array, and for each different *type*, you save those that have the same name, then you call a second function that will check the highest between them.
secondly, this other function works like this:
{
var array = the array you just got from the first function;
var highest= 0;
var index_highest = 0;
for (i=0; i<=highest;i++)
if (array[i]['value']>highest) {
highest = array[i];
index_highest = i;
}
}
i swear i wrote that with proper tabbing, but the chat just removes all spaces
yea no good.
 
8:47 PM
Try groups of four spaces
even in front of the {
 
i did
it works on answers, but not here i think
 
@ShadowKras it worked for me above, maybe because I only had code in that post
 
nope, but you got the idea, right?
 
yes
@ShadowKras I think I will go this slightly different way that looks easier to me: cycling through the original array, looking for bonus type. Pick variable name, if the corresponding checkbox is checked evaluate its value against the previously stored one, if it's higher save both the bonus and the name. Is that working in your book?
 
if it works, it works!
to make things easier, i would also create a function to check if a bonus type is stackable or not (checking the type against dodge and untyped and returning true/false).
 
9:05 PM
@ShadowKras seems like a plan
 
var IsStackableBuff = function(type){
    return (type === 'dodge' || type === 'untyped');
}
ah, got it now. The very first line of code has to start with four spaces.
 
9:37 PM
Another flareup in the tabs-vs.-four-spaces internicene wars?
 
@nitsua60 no, SE code formatting
 
function highest(type){
	var maxValue=0;
	var name="";
	for (i=0; i<buffArray.length; i++) {
		if (buffArray[i]['type']='type' && buffArray[i]['name']=1 {
			if buffArray[i]['value']>maxValue {
				maxValue=buffArray[i]['value'];
				name=buffArray[i]['name'];
			}
		}
	}
	return {"name":name;"value":maxValue};
}
I think this should work if I save my checkbox status inside the object itself, I'm just not sure about the return
 
if (buffArray[i]['type']='type' <- type here has to be without ' ', no? I would give it a different name so there is no confusion.
 
ah, right, well spotted
 
9:52 PM
your comparison operators have to be either == (same value) or === (same value and type) aswell.
 
return '{"name":"' + name + ';"value":' + maxValue + '}'; ?
 
your return was fine, imo.
 
I'm not sure, objects want the name in ""
 
you have no reason to stringify an object unless it's to save it to a file or transmit it over HTTP to a server
 
Will look for examples
 
9:56 PM
given that its an object with two properties, you could access it like this:
highest('armor')['name'] to obtain the name and highest('armor')['value'] to obtain the value.
 
iiiiiiiiiMh ok, so if I say "name":varname it will automatically output "name":"varnamecontent"?
 
@Zachiel Objects don't need their name defined as a string, but they do need to be set & accessed via a string if the product coincides with a reserved keyword.
 
it will output an object like this:

{ 'name': 'bonus name', 'value': 4 }
since the variable you defined as name is a string, it will come with 'simple apostrophes'.
 
the definition var thing = {"case": "foo"} is fine, the definition var thing = {case: "foo"} is not. thing["case"] is fine, thing.case is not.
 
while the variable that is an integer has no apostrophes unless you convert it to a string.
ie: value.toString()
 
9:59 PM
(this is why DOM objects have the .className property -- they couldn't call it .class because class is a reserved keyword)
 
@doppelgreener wait
I want {"name":"luck","value":3}
because I can't return two separate values, right? So I need to embed them in an object
 
correct
 
So you're telling me I can also have {"name":luck,"value":3}?
 
He is talking about reserved keywords, you cant have a property with the same name as a reserved keyword. Your first return was fine.
 
no, i'm telling you that you can have {name: "luck", value: 3}
{name: luck, value: 3} would work if luck was a variable, and it would pass on the value of that variable.
 
10:05 PM
but {name: "luck", value: 3, class: 'whatever'} wouldnt be fine because class is reserved, you would have to turn it into a string.
{name: "luck", value: 3, "class": 'whatever'}
 
@doppelgreener ok that's what I wanted to know. but "luck" is a variable ionly inside the function, when I pass the value it needs to pass the value stored in the variable, and since that is a string, it has to be in quotes. I guess I solve this by making sure the stored text inside the variable includes the quotes
 
You dont have to, when you defined it's value, it became a string:
var name="";
and even if you didnt, when you used it inside your loop, the value it obtained was a string:
name=buffArray[i]['name'];
so, when you finally call name, it already contains the apostrophes.
var newstring = name;

return newstring;

newstring will be contained within apostrophes.
 
@Zachiel well here's the thing. var luck = "foo" means i can return luck, and the function I'm passing back to would see the string "foo" returned. I could also return {name: luck, value: 3}, and that function it's returned to would see {name: "foo", value: 3}.
if you pass back "luck" you're passing back the string "luck". if you pass back the variable luck you'd be passing back the string "foo" you assigned to the variable luck.
it doesn't matter that the variable luck only exists inside that function, because you're passing back its value regardless of whether the variable itself will cease to exist in a moment.
 
Tomorrow I will populate a small database and see how it goes.
ta ta for now
 
later
 
10:19 PM
ttfn
 
10:56 PM
Are 'list usage' questions On Topic? cv the Psi Power Pt q now on the front.
 
1
Q: How to deal with tug-of-war close reopens?

WrongOnTheInternetSo this question has a very odd edit history, being closed as primarily opinion based by five users, re-opened by five-users, and finally being closed by a diamond mod. The reason this is such a strange question is that all of those open/close votes came consecutively, with no additional edits h...

 
00:00 - 20:0020:00 - 00:00

« first day (2431 days earlier)      last day (2549 days later) »