inherit
217342
0
Oct 7, 2015 7:39:08 GMT -8
nemolionak3
26
January 2015
nemolionak3
|
Post by nemolionak3 on Sept 9, 2015 7:12:47 GMT -8
Hello, I'm trying to make a patch (for personal use) for this plugin What I'm trying to do right now is change the time limit to be per-account. (example of this: "admin" gave +karma to "shortyverrett94", "admin" can't give +karma to "shortyverrett94" for X minutes, but "admin" can give +karma to any other account) HERE is the code that I put into a javascript component in the plugin (which is supposed to act as a "patch"). (The arguments for the function "i" and "n" stand for "current user id" and "the name of the user you're giving karma to" respectively) I have a key made, which is called "timelimit", and is a user private key. When it gets to line 15: if(ksp.key[n] == gltl || new Date().getTime() >= ksp.key[n]) { It gives me this error: (I have some console.log calls in my code, hence "tlkey: undefined" and "tlkey_afterformat: undefined")I understand the error, but why is the key, which I'm trying to get a property's value of, undefined? If you need more of the code (to understand some parts of the script or how the function is called), HERE is the entirety of my patch's code, and since I'm not sure if I can paste the code of shorty's plugin here, I won't do that. Thanks for any reply
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 9, 2015 18:35:39 GMT -8
Hello, I'm trying to make a patch (for personal use) for this plugin What I'm trying to do right now is change the time limit to be per-account. (example of this: "admin" gave +karma to "shortyverrett94", "admin" can't give +karma to "shortyverrett94" for X minutes, but "admin" can give +karma to any other account) HERE is the code that I put into a javascript component in the plugin (which is supposed to act as a "patch"). (The arguments for the function "i" and "n" stand for "current user id" and "the name of the user you're giving karma to" respectively) I have a key made, which is called "timelimit", and is a user private key. When it gets to line 15: if(ksp.key[n] == gltl || new Date().getTime() >= ksp.key[n]) { It gives me this error: (I have some console.log calls in my code, hence "tlkey: undefined" and "tlkey_afterformat: undefined")I understand the error, but why is the key, which I'm trying to get a property's value of, undefined? If you need more of the code (to understand some parts of the script or how the function is called), HERE is the entirety of my patch's code, and since I'm not sure if I can paste the code of shorty's plugin here, I won't do that. Thanks for any reply Assuming you are in fact doing things right. Let's assume you have a new key. The user karma is going to say 0. But in all reality, that's just a placeholder. There is nothing saved to the key until someone adds or takes away karma. Each key starts out as undefined and will remain so until it is set. The only other way a key will be undefined is if you pass a .get({object_id:}) and the id is a user that has not been loaded on the page at the moment of this call
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 9, 2015 18:36:40 GMT -8
Debugging and experience is a long road so if this does not fix your problem, post some code and links to your forum
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,986
December 2005
horace
Wormo's Mini-Profile
|
Post by Chris on Sept 10, 2015 0:41:44 GMT -8
The key does not return an object where you can access the values directly (e.g. sks.key[n]) but rather as a "class-ish" with methods to store, manipulate and access the underlying data. So you would need to chop of the call to get() when defining the value for key so you can then access the methods of the key There is of course a way to directly access the underlying key data ( proboards.plugin.keys.data["timelimit"]) but we're being steered away from the proboards namespace and encouraged to use pb, the implication of course being your code could fail down the road if you choose to ignore the deprecation warnings. Your undefined is more than likely coming from grabbing a specific key value (for the current user id in this case) which may not yet exist in the key as P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ pointed out.
|
|
inherit
217342
0
Oct 7, 2015 7:39:08 GMT -8
nemolionak3
26
January 2015
nemolionak3
|
Post by nemolionak3 on Sept 10, 2015 10:24:20 GMT -8
Oh, I didn't realise that, derp. Even after trying for around 2 hours, I couldn't figure it out. This is the forum I use for testing/plugin development purposes: LINK (it used to be a community, but it's been dead for a while so I turned it into my test forum) And here's the the current code of the plugin patch: link to pastebin (you could easily find the code you need in the developer tools, but for convenience's sake, here it is) I don't get any error directly now, but I know that the object (key) property I'm trying to access is undefined, and I'm pretty sure that the key is still undefined despite this being in place: var karma_system_patch = { key: pb.plugin.key('timelimit') } Basically, it gets stuck at this: if(ksp.key[i] == 0 || new Date().getTime() >= ksp.key[i]) { If somebody would be so nice as to correct my code, or tell me what exactly is wrong with it, I'd really appreciate it. Thanks
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 10, 2015 13:48:07 GMT -8
Oh, I didn't realise that, derp. Even after trying for around 2 hours, I couldn't figure it out. This is the forum I use for testing/plugin development purposes: LINK (it used to be a community, but it's been dead for a while so I turned it into my test forum) And here's the the current code of the plugin patch: link to pastebin (you could easily find the code you need in the developer tools, but for convenience's sake, here it is) I don't get any error directly now, but I know that the object (key) property I'm trying to access is undefined, and I'm pretty sure that the key is still undefined despite this being in place: var karma_system_patch = { key: pb.plugin.key('timelimit') } Basically, it gets stuck at this: if(ksp.key[i] == 0 || new Date().getTime() >= ksp.key[i]) { If somebody would be so nice as to correct my code, or tell me what exactly is wrong with it, I'd really appreciate it. Thanks I'm not good with namespaces. Perhaps Chris can take a quick look at your pastebin code and understand your problem. Plus I dont see the error or the karma system running on your site perhaps its set to staff only?
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,986
December 2005
horace
Wormo's Mini-Profile
|
Post by Chris on Sept 10, 2015 18:46:09 GMT -8
Oh, I didn't realise that, derp. Even after trying for around 2 hours, I couldn't figure it out. This is the forum I use for testing/plugin development purposes: LINK (it used to be a community, but it's been dead for a while so I turned it into my test forum) And here's the the current code of the plugin patch: link to pastebin (you could easily find the code you need in the developer tools, but for convenience's sake, here it is) I don't get any error directly now, but I know that the object (key) property I'm trying to access is undefined, and I'm pretty sure that the key is still undefined despite this being in place: var karma_system_patch = { key: pb.plugin.key('timelimit') } Basically, it gets stuck at this: if(ksp.key[i] == 0 || new Date().getTime() >= ksp.key[i]) { If somebody would be so nice as to correct my code, or tell me what exactly is wrong with it, I'd really appreciate it. Thanks You've changed it but still haven't changed the access method if(ksp.key.get(i) == 0 || new Date().getTime() >= ksp.key.get(i)) { That ksp.key[x] occurs in several other places as well. Perhaps I am missing it or maybe you haven't added it yet but I am not seeing where your private user key "timelimit" is being used to store a value anywhere in the code. I see several sks.key.set() but no ksp.key.set() to store any changes to the key back to the server. I assume you are planning to use that key to hold a more extensive list of users who have had their karmas victimized by a particular user since Shorty limits the history in his key only to the last four incoming karmas and the last four outgoing karmas (due to space constraints). If memory serves you're looking to limit each user to a single point of give and/or take for any other user (forever, no time limit) so might I suggest a key in an array format containing the IDs of the victims, example: [1, 65613, -201984, 999, -666]The negatives would signify a takeaway (thus allowing only for a giveback action) and the positives would allow only for a take back action. Perhaps I am misunderstanding what you're after (I do that sometimes) in which case ignore whatever I just said. EDIT
I just noticed this line in your code ksp.key[n] = parseInt(new Date().getTime() + (pb.plugin.get('karma_system_patch').settings.paTimelimit * 60000)); which looks to be saving a time code to the key (in memory, not to server) meaning I was way off in divining your intent. That method would of course require direct access to the underlying key structure effectively cutting out the middleman ( .get() and .set()) but as mentioned earlier, access through the "proboards" namespace has been deprecated (but still enumerable) which is how you would get there. That of course now has me thinking whether or not it would be possible to define getters and setters for a key so the way that you're using it can become a viable way of doing it similar to the way the middlemen setItem() and .getItem() are cut out of localStorage allowing for localStorage.myKeyName = value; instead of localstorage.setItem("myKeyName",value)
|
|
inherit
217342
0
Oct 7, 2015 7:39:08 GMT -8
nemolionak3
26
January 2015
nemolionak3
|
Post by nemolionak3 on Sept 11, 2015 5:34:56 GMT -8
Oh, I didn't realise that, derp. Even after trying for around 2 hours, I couldn't figure it out. -snip- If somebody would be so nice as to correct my code, or tell me what exactly is wrong with it, I'd really appreciate it. Thanks You've changed it but still haven't changed the access method if(ksp.key.get(i) == 0 || new Date().getTime() >= ksp.key.get(i)) { That ksp.key[x] occurs in several other places as well. -snip- EDIT
I just noticed this line in your code ksp.key[n] = parseInt(new Date().getTime() + (pb.plugin.get('karma_system_patch').settings.paTimelimit * 60000)); -snip- I'm sorry for not making my intentions clear, what I want to do is when somebody gives karma to someone, it adds a new property to the key of the currently logged in user (hence private user key), which stores the ID of the user you gave karma to, and the time code at which you did it+the time limit. If you try to give karma to the same person again, it checks to see that the ID is the same, and then checks if the time limit has passed already, if it has, it adds rep and sets a new time code to the ID - and if the time limit hasn't passed yet, then an alert window appears saying that you need to wait until X (where X is the time code stored in the key under the ID) the key should then be in the following format: timelimit(<currently_logged_in_userID>) = { <ID of the user you gave karma to>: <time code at which you gave karma + the time limit set in the settings> EXAMPLE: 14: 1441975543023 7: 1441978546028 etc: etc } You said something about the old proboards namespace, shorty's plugin also uses some proboards.X methods, so the whole thing would stop working sooner or later... How would I go about adding the ID/VALUE pairs into the key dynamically utilizing the old namespace?
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 11, 2015 13:02:41 GMT -8
You've changed it but still haven't changed the access method if(ksp.key.get(i) == 0 || new Date().getTime() >= ksp.key.get(i)) { That ksp.key[x] occurs in several other places as well. -snip- EDIT
I just noticed this line in your code ksp.key[n] = parseInt(new Date().getTime() + (pb.plugin.get('karma_system_patch').settings.paTimelimit * 60000)); -snip- I'm sorry for not making my intentions clear, what I want to do is when somebody gives karma to someone, it adds a new property to the key of the currently logged in user (hence private user key), which stores the ID of the user you gave karma to, and the time code at which you did it+the time limit. If you try to give karma to the same person again, it checks to see that the ID is the same, and then checks if the time limit has passed already, if it has, it adds rep and sets a new time code to the ID - and if the time limit hasn't passed yet, then an alert window appears saying that you need to wait until X (where X is the time code stored in the key under the ID) the key should then be in the following format: timelimit(<currently_logged_in_userID>) = { <ID of the user you gave karma to>: <time code at which you gave karma + the time limit set in the settings> EXAMPLE: 14: 1441975543023 7: 1441978546028 etc: etc } You said something about the old proboards namespace, shorty's plugin also uses some proboards.X methods, so the whole thing would stop working sooner or later... How would I go about adding the ID/VALUE pairs into the key dynamically utilizing the old namespace? timelimit(idOfTheUserGivenTo)={//it would have to be taken from wherever it's stored in shorty's code return {idOfTheUserGivenTo : (pb.data('serverDate')+timeOnPageSinceLoaded+timeLimitInKey)} }//timeOnPageSinceLoaded should be a setInterval of 1000 miliseconds that keeps track of seconds past load or some other method You can get the current user id with pb.data('user').id however you don't need it in this function since it will be saved in the private user key which doesn't require the user's id to save since it will automatically detect the current user in the set function.
|
|
inherit
217342
0
Oct 7, 2015 7:39:08 GMT -8
nemolionak3
26
January 2015
nemolionak3
|
Post by nemolionak3 on Sept 11, 2015 21:36:07 GMT -8
I'm sorry for not making my intentions clear, what I want to do is when somebody gives karma to someone, it adds a new property to the key of the currently logged in user (hence private user key), which stores the ID of the user you gave karma to, and the time code at which you did it+the time limit. If you try to give karma to the same person again, it checks to see that the ID is the same, and then checks if the time limit has passed already, if it has, it adds rep and sets a new time code to the ID - and if the time limit hasn't passed yet, then an alert window appears saying that you need to wait until X (where X is the time code stored in the key under the ID) the key should then be in the following format: timelimit(<currently_logged_in_userID>) = { <ID of the user you gave karma to>: <time code at which you gave karma + the time limit set in the settings> EXAMPLE: 14: 1441975543023 7: 1441978546028 etc: etc } You said something about the old proboards namespace, shorty's plugin also uses some proboards.X methods, so the whole thing would stop working sooner or later... How would I go about adding the ID/VALUE pairs into the key dynamically utilizing the old namespace? timelimit(idOfTheUserGivenTo)={//it would have to be taken from wherever it's stored in shorty's code return {idOfTheUserGivenTo : (pb.data('serverDate')+timeOnPageSinceLoaded+timeLimitInKey)} }//timeOnPageSinceLoaded should be a setInterval of 1000 miliseconds that keeps track of seconds past load or some other method You can get the current user id with pb.data('user').id however you don't need it in this function since it will be saved in the private user key which doesn't require the user's id to save since it will automatically detect the current user in the set function. So where do I put this code? In a format_timelimitkey function? Or do I use that whenever I need to add a value to the key? Also, my original issue is still unsolved.. Whenever I try to use the key somehow it always reports undefined, no matter what I do. I think that if I could somehow figure out how to "initialize" the key, I could do the rest of the things I want to do with it, so my main issue is that I don't know how to use the timelimit key.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 11, 2015 23:03:47 GMT -8
timelimit(idOfTheUserGivenTo)={//it would have to be taken from wherever it's stored in shorty's code return {idOfTheUserGivenTo : (pb.data('serverDate')+timeOnPageSinceLoaded+timeLimitInKey)} }//timeOnPageSinceLoaded should be a setInterval of 1000 miliseconds that keeps track of seconds past load or some other method You can get the current user id with pb.data('user').id however you don't need it in this function since it will be saved in the private user key which doesn't require the user's id to save since it will automatically detect the current user in the set function. So where do I put this code? In a format_timelimitkey function? Or do I use that whenever I need to add a value to the key? Also, my original issue is still unsolved.. Whenever I try to use the key somehow it always reports undefined, no matter what I do. I think that if I could somehow figure out how to "initialize" the key, I could do the rest of the things I want to do with it, so my main issue is that I don't know how to use the timelimit key. My example was solely based on your format. I have no idea if that's how you want it structured to suit your needs. Personally I would write functions outside of his namespace because I find it harder to use namespaces even though it's easier in the long run. I thought you knew where your code was going. Perhaps eton would know more, I'm really not understanding the whole concept your trying to solve at the moment. And I guess eton confused you with how to initialize your key with his response? Cause I thought he mentioned what to do.
|
|
inherit
217342
0
Oct 7, 2015 7:39:08 GMT -8
nemolionak3
26
January 2015
nemolionak3
|
Post by nemolionak3 on Sept 12, 2015 2:45:43 GMT -8
So where do I put this code? In a format_timelimitkey function? Or do I use that whenever I need to add a value to the key? Also, my original issue is still unsolved.. Whenever I try to use the key somehow it always reports undefined, no matter what I do. I think that if I could somehow figure out how to "initialize" the key, I could do the rest of the things I want to do with it, so my main issue is that I don't know how to use the timelimit key. My example was solely based on your format. I have no idea if that's how you want it structured to suit your needs. Personally I would write functions outside of his namespace because I find it harder to use namespaces even though it's easier in the long run. I thought you knew where your code was going. Perhaps eton would know more, I'm really not understanding the whole concept your trying to solve at the moment. And I guess eton confused you with how to initialize your key with his response? Cause I thought he mentioned what to do. Basically, I have no idea why, but my key is still undefined. That's the main problem. when I try to do ksp.key (which SHOULD reffer to a property which has a user id as its name, and the time code as its value - but what it does instead is nothing. It doesn't do anything, because it's undefined, and I don't know why). I realise that I somehow have to first "initialize" the key, but I have no clue how to do that, or what exactly I have to initialize... I thought that the keys are ready for use as soon as you make one, just add a property with a value to it and you can access/change that value whenever you want Another problem that I know I will face is being able to "dynamically" add id/timecode pairs to the user key. Simply put, "adding" id/timecode pairs to the key - because when you give karma, I want the script to save the ID and timecode into the key.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 12, 2015 19:17:15 GMT -8
My example was solely based on your format. I have no idea if that's how you want it structured to suit your needs. Personally I would write functions outside of his namespace because I find it harder to use namespaces even though it's easier in the long run. I thought you knew where your code was going. Perhaps eton would know more, I'm really not understanding the whole concept your trying to solve at the moment. And I guess eton confused you with how to initialize your key with his response? Cause I thought he mentioned what to do. Basically, I have no idea why, but my key is still undefined. That's the main problem. when I try to do ksp.key (which SHOULD reffer to a property which has a user id as its name, and the time code as its value - but what it does instead is nothing. It doesn't do anything, because it's undefined, and I don't know why). I realise that I somehow have to first "initialize" the key, but I have no clue how to do that, or what exactly I have to initialize... I thought that the keys are ready for use as soon as you make one, just add a property with a value to it and you can access/change that value whenever you want Another problem that I know I will face is being able to "dynamically" add id/timecode pairs to the user key. Simply put, "adding" id/timecode pairs to the key - because when you give karma, I want the script to save the ID and timecode into the key. You are making a new key, so is it going to be an object or an array? If you are setting the key it would be pb.plugin.key('timelimit').set(objectOrArray) if you are getting the key it would be pb.plugin.key('timelimit').get() The key will be undefined until you set it. There is no need to initialize the key on proboards servers. var keydata = pb.plugin.key('timelimit').get() if(keydata==undefined) {keydata = objectOrArray} objectOrArray being whatever default data the key should hold Then you just start managing the data away. After the user clicks a button it would be keydata.push(newValue)//if array pb.plugin.key('timelimit').set(keydata) And you are done.
|
|
inherit
217342
0
Oct 7, 2015 7:39:08 GMT -8
nemolionak3
26
January 2015
nemolionak3
|
Post by nemolionak3 on Sept 13, 2015 1:30:37 GMT -8
Basically, I have no idea why, but my key is still undefined. That's the main problem. when I try to do ksp.key (which SHOULD reffer to a property which has a user id as its name, and the time code as its value - but what it does instead is nothing. It doesn't do anything, because it's undefined, and I don't know why). I realise that I somehow have to first "initialize" the key, but I have no clue how to do that, or what exactly I have to initialize... I thought that the keys are ready for use as soon as you make one, just add a property with a value to it and you can access/change that value whenever you want Another problem that I know I will face is being able to "dynamically" add id/timecode pairs to the user key. Simply put, "adding" id/timecode pairs to the key - because when you give karma, I want the script to save the ID and timecode into the key. You are making a new key, so is it going to be an object or an array? If you are setting the key it would be pb.plugin.key('timelimit').set(objectOrArray) if you are getting the key it would be pb.plugin.key('timelimit').get() The key will be undefined until you set it. There is no need to initialize the key on proboards servers. var keydata = pb.plugin.key('timelimit').get() if(keydata==undefined) {keydata = objectOrArray} objectOrArray being whatever default data the key should hold Then you just start managing the data away. After the user clicks a button it would be keydata.push(newValue)//if array pb.plugin.key('timelimit').set(keydata) And you are done. Thanks, for all the replies! I finally understand how I'm supposed to do this, and I've seemed to have figured it out. Again, thanks for all the help.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 13, 2015 1:32:38 GMT -8
You are making a new key, so is it going to be an object or an array? If you are setting the key it would be pb.plugin.key('timelimit').set(objectOrArray) if you are getting the key it would be pb.plugin.key('timelimit').get() The key will be undefined until you set it. There is no need to initialize the key on proboards servers. var keydata = pb.plugin.key('timelimit').get() if(keydata==undefined) {keydata = objectOrArray} objectOrArray being whatever default data the key should hold Then you just start managing the data away. After the user clicks a button it would be keydata.push(newValue)//if array pb.plugin.key('timelimit').set(keydata) And you are done. Thanks, for all the replies! I finally understand how I'm supposed to do this, and I've seemed to have figured it out. Again, thanks for all the help. Awesome, if you ever need help we're here.
|
|