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 Oct 2, 2015 19:49:24 GMT -8
XD the second part is a nope the first part is an argument in progress Have you tried wrapping the code into its own function? That way you can call it multiple times. Once on document ready and i guess the others as a button. Or u could just paste the code three times lol.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Oct 2, 2015 23:24:32 GMT -8
How would I do that and I mean more they get one loaded as soon as they visit the page then they hit a button it refreshes to show a new one, for a maximum of 3 times including the very first load. There should also be another button that is along the lines of "I pick this one" which can be used any time, but after 3 attempts becomes the only click able option and the choice is saved for 24hrs
|
|
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 Oct 3, 2015 13:59:23 GMT -8
How would I do that and I mean more they get one loaded as soon as they visit the page then they hit a button it refreshes to show a new one, for a maximum of 3 times including the very first load. There should also be another button that is along the lines of "I pick this one" which can be used any time, but after 3 attempts becomes the only click able option and the choice is saved for 24hrs Well i would add a private user key that saves the day and how many attempts. But that would also mean not generating a number on page load and only by button. So that it saves the key on button press. If the day in the key matches today then add to the counter. If not reset the counter.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Nov 20, 2015 0:06:00 GMT -8
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 20, 2015 6:55:06 GMT -8
Boy_Wonder , Will keep this as simple as possible, as weighting can be as easy or hard as you want to make it. I'll show you a very simple solution that should be fine for what you are doing, it's definitely not the most efficient way if the "table" was a lot bigger, but for starting out, it will be easier for you to understand and modify. // Note: Ignore the bitwise operators, it's just what I prefer to use, "parseInt" and "Math.floor" // is fine, and I made a note which one goes where if you feel more comfortable using them.
var plugin = pb.plugin.get("equestriad_random_event_genera"); var settings = (plugin && plugin.settings)? plugin.settings : false;
if(settings && settings.events_and_weighting){ var event_table = []; // Here we store the events. We pull from this table later on. var events = settings.events_and_weighting; for(var e = 0, l = events.length; e < l; e ++){ // We want at least 1 entry right? So if no weight is set // then default to 1. We also "parseInt" the value. var weight = (~~ events[e].weight) || 1;
// "weight" just indicates the number of times the event is added to the table. // The bigger the weight, the more times it is added. while(weight){ // We push the whole event to the table, we could reduce the amount of // duplicate data being stored, but for this example, it should be fine.
event_table.push(events[e]); weight --; } } // Now print out a random event. // Note: "Math.floor" is done on the index here console.log(event_table[~~ (Math.random() * event_table.length)]); } Hopefully that weighting solution is easier for you to understand than the one you currently implemented (which looks like it was from a very old tutorial).
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Nov 20, 2015 7:32:07 GMT -8
Weighting is done through the plugin I'm trying to keep it simple as it were -goes to try that-
Okay I'm getting "syntax error: unexpected end of input" and I'm not sure what that means (I understand ones like 'unexpected symbol' but I don't get 'unexpected end of input'
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 20, 2015 7:54:23 GMT -8
Weighting is done through the plugin I'm trying to keep it simple as it were -goes to try that- Okay I'm getting "syntax error: unexpected end of input" and I'm not sure what that means (I understand ones like 'unexpected symbol' but I don't get 'unexpected end of input' You can't just copy and paste that into your plugin (edit: actually you could have lol), it needs a little more (plus you missed a closing curly brace, which is likely the cause) Weighting is set in the auto form for each event. With the solution above, you need to think of the weight as being the amount of times that event is added to a list. The more times it appears, the more likely it is to be selected. It's a very simple solution when starting out, easy to implement, easy to understand how it works. Still some work to be done on your part to use / display the event. The console will show you the event chosen, you need to do some magic with it now $(document).ready(function(){
(function(){ return { init: function(){ // Note: Ignore the bitwise operators, it's just what I prefer to use, "parseInt" and "Math.floor" // is fine, and I made a note which one goes where if you feel more comfortable using them.
var plugin = pb.plugin.get("equestriad_random_event_genera"); var settings = (plugin && plugin.settings)? plugin.settings : false;
if(settings && settings.events_and_weighting){ var event_table = []; // Here we store the events. We pull from this table later on. var events = settings.events_and_weighting; for(var e = 0, l = events.length; e < l; e ++){ // We want at least 1 entry right? So if no weight is set // then default to 1. We also "parseInt" the value. var weight = (~~ events[e].weight) || 1;
// "weight" just indicates the number of times the event is added to the table. // The bigger the weight, the more times it is added. while(weight){ // We push the whole event to the table, we could reduce the amount of // duplicate data being stored, but for this example, it should be fine.
event_table.push(events[e]); weight --; } } // Now print out a random event. // Note: "Math.floor" is done on the index here console.log(event_table[~~ (Math.random() * event_table.length)]); // Do something with it here. } } }; })().init();
});
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Nov 20, 2015 8:25:13 GMT -8
xD Thanks Peter - I did try with my existing document ready command but it didn't like that
(I kinda ignored it for a while as proboards keeps confusing me with its different list formats for build vs manage plugin)
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Dec 16, 2015 22:09:05 GMT -8
Either I need to input more Dr Pepper/stop trying to do things with javascript at 4am/being really really dense. So I've so far moved the code to the point it only shows on one page. I have its new home nice and ready for it equestriads3.com/page/random-event-generatBut it apparently doesn't want to sit in its new home. Its not throwing any errors. It just is refusing to show up. I've tried all the tricks I know but nope. It's stubbornly saying "No I don't want to play" help? I've tried appending it to the div. Naddah. I've tried setting it as the innerHTML still nope.
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Dec 17, 2015 2:10:15 GMT -8
Boy_Wonder , Ok, so 2 issues: 1. The ID doesn't need to include the hash symbol, unlike jQuery (selector). Change this... document.getElementById("#random-stuff-here").innerHTML = randomOutput To this... document.getElementById("random-stuff-here").innerHTML = randomOutput jQuery example... $("#random-stuff-here").html(randomOutput) 2. The randomOutput value is an object with the following keys: - description - name - type - weight So if you wanted to show the description: document.getElementById("random-stuff-here").innerHTML = randomOutput.description Then you could have another element for the name... document.getElementById("random-stuff-here-title").innerHTML = randomOutput.name
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Dec 17, 2015 2:53:58 GMT -8
oooh! Thanks for that! I'm 90% certain I need to stop trying to code at 4.00am XD
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Dec 17, 2015 7:23:24 GMT -8
Boy_Wonder, Some of my best coding is done at silly o'clock I think the worst thing I done recently that I can remember was this... $(function(){ (function(){ return function(){ return { init: function(){ console.log("Hello from within"); } } }; })()().init() }); Don't ask what I was trying to do, it was at a time where I could barely stay awake and was experimenting with an API.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Dec 17, 2015 7:26:43 GMT -8
Boy_Wonder , Some of my best coding is done at silly o'clock I think the worst thing I done recently that I can remember was this... $(function(){ (function(){ return function(){ return { init: function(){ console.log("Hello from within"); } } }; })()().init() }); Don't ask what I was trying to do, it was at a time where I could barely stay awake and was experimenting with an API. xDD apparently I just typo unless I'm doing HTML. Css tends to get interesting.
|
|