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 Jun 25, 2014 21:51:56 GMT -8
$( document ).ready(function() {
var otmplace =pb.plugin.get('placeable_otm');
if(otmplace.settings.random_or_static === "random"){
var otmRandom = pb.plugin.get('placeable_otm').settings.otms;
$('div#OTM').append('All the finished things');
} else {
/*OTM Array*/
$('div#OTM').append('<div style="text-align: center;"><a href="'+ otmplace.settings.otms.character_link +'">'+ otmplace.settings.otms.character_name +'</a><br> <img src="'+ otmplace.settings.otms.character_avatar +'" title="'+ otmplace.settings.otms.character_name +'"><br><b> '+ otmplace.settings.otms.otm_name +'</b></div>');
}
}); So far the top part isn't done, however I'm having problems getting the output (Which comes from a autoform) to work, as its just showing Undefined (http://abstractive.freeforums.net/ < Test site here)
Also another question for the top part I need to have it set out the same as the bottom part for the OTMs but it would be a randomised option. I'm pretty sure I know how to do randomization, and I think I've asked how to do it using the autoform for the length etc. Its just how in the output I'd get it to give the exact field details. I'm not sure if I'm making sense here
|
|
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"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jun 26, 2014 0:31:49 GMT -8
$( document ).ready(function() {
var otmplace =pb.plugin.get('placeable_otm');
if(otmplace.settings.random_or_static === "random"){
var otmRandom = pb.plugin.get('placeable_otm').settings.otms;
$('div#OTM').append('All the finished things');
} else {
/*OTM Array*/
$('div#OTM').append('<div style="text-align: center;"><a href="'+ otmplace.settings.otms.character_link +'">'+ otmplace.settings.otms.character_name +'</a><br> <img src="'+ otmplace.settings.otms.character_avatar +'" title="'+ otmplace.settings.otms.character_name +'"><br><b> '+ otmplace.settings.otms.otm_name +'</b></div>');
}
}); So far the top part isn't done, however I'm having problems getting the output (Which comes from a autoform) to work, as its just showing Undefined (http://abstractive.freeforums.net/ < Test site here) Also another question for the top part I need to have it set out the same as the bottom part for the OTMs but it would be a randomised option. I'm pretty sure I know how to do randomization, and I think I've asked how to do it using the autoform for the length etc. Its just how in the output I'd get it to give the exact field details. I'm not sure if I'm making sense here It's showing undefined because no index into the array is being specified. The comment on the portion that handles the "static" mode clearly understands that this is an array but the line that actually accesses that array forgets to give an index so we know which element in that array is being accessed. Example: otmplace.settings.otms[0].character_linkEven though there is currently only one line in that autoform array (at index zero) we still need to specify an index to properly access an entry in the array. proboards.plugin._plugins["placeable_otm"] = { settings : { "random_or_static" : "static", "otms" : [{ "character_link" : "http://shieldrp.com/user/1", "character_name" : "Admin", "character_avatar" : "http.../thegeekfiles/shield-logo-marvel-movies.jpg", "otm_name" : "Member Of the Month" } ] } };
As for randomly selecting an entry in that array, a crucial ingredient would be knowing the length of that array. var otmRandom = Math.floor(Math.random() * otmplace.settings.otms.length);
That line would randomly pick a number (integer) between 0 and (1 less than) the total length of the array. Access the array with that randomly chosen index and you've now randomly selected an entry in that array. Example: otmplace.settings.otms[otmRandom].character_link
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jun 26, 2014 0:32:32 GMT -8
autoforms are arrays, so you have to access them like arrays
otmplace.settings.otms[x].character_avatar
where x is the entry index in the array. you have to determine how you get x however. if you are having admin pick one as a static that always shows, you could make a UI variable where they enter a number starting at 0. or you could get a random number using
x=parseInt(Math.random() * otmplace.settings.otms.length)
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jun 26, 2014 0:33:20 GMT -8
wow eton.. that was spooky...
|
|
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 Jun 26, 2014 5:04:10 GMT -8
Thanks both of you!
Edit: Another question. For static what I'm looking for is it displays all the inputs. So say someone has 5 OTMs they want to show, I'd want to display all of them set, how would I do that?
|
|
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"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jun 26, 2014 18:04:50 GMT -8
Thanks both of you! Edit: Another question. For static what I'm looking for is it displays all the inputs. So say someone has 5 OTMs they want to show, I'd want to display all of them set, how would I do that? yw As a famous Jedi once said, use the for loop: for (index = 0, len = otmplace.settings.otms.length; index < len; index = index + 1) { $('div#OTM').append( '<div style="text-align:center; float:left; margin:5px;"><a href="' + otmplace.settings.otms[index].character_link + '">' + otmplace.settings.otms[index].character_name + '</a><br> <img src="' + otmplace.settings.otms[index].character_avatar + '" title="' + otmplace.settings.otms[index].character_name + '"><br><b> ' + otmplace.settings.otms[index].otm_name + '</b></div>' ); }
|
|
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 Jun 26, 2014 21:44:47 GMT -8
Do I need to do anything particular to make sure it doesn't end up locking everything up?
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jun 27, 2014 0:17:24 GMT -8
that usually only happens when you use a while loop. if something goes wrong it should just quit a for loop and exit back to the top calling function.
|
|
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 Jun 27, 2014 1:19:44 GMT -8
Okay! Thanks for that! I knew one of those two could cause it so I just wanted to check
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jun 27, 2014 1:30:05 GMT -8
if you are really worried about a while loop, you could always set a variable at 0, and every iteration of the while loop, increment it by 1. then in the while loop, check its value. if its value is way higher then a number you decide is too high, exit the while loop with an alert. that way you dont have to sit there and wait until the browser runs out of memory before it throws up its own alert. it really depends on the purpose of the loop though. if you know there shouldnt be more then 10 levels of recursion on something, set the number to 15 or something. if you think the number might need to be higher, set it higher. when you finally figure out where you went wrong in the infinite loop, you can always just remove the loopbreaker coding.
|
|
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 Jun 27, 2014 1:39:37 GMT -8
Ahh! -learning something new- Meanwhile I've found a new problem but I can't find where its not going right. To let a person chose between random (which should only show one of the autoform field outputs) and static (shows all) However either way its just selecting the static option. I'm again sure I've just goofed up somewhere in my coding, but my eyes seem to be too tired to pick it up /* Idea by Shakiah, coded by Hawkeye, with much help by Wormo and Eton Bones */
$( document ).ready(function() {
var otmplace =pb.plugin.get('placeable_otm');
if(otmplace.settings.random_or_static === "random"){
/*Random stuff*/
console.log("Random is chosen");
var randOTM = parseInt(Math.random() * otmplace.settings.otms.length);
$('div#OTM').append('<div style="text-align: center;"><a href="'+ otmplace.settings.otms[randOTM].character_link +'">'+ otmplace.settings.otms[randOTM].character_name +'</a><br> <img src="'+ otmplace.settings.otms[randOTM].character_avatar +'" title="'+ otmplace.settings.otms.character_name +'" style="width: '+ otmplace.settings.avatar_width +'px; height: auto;"><br><b> '+ otmplace.settings.otms[randOTM].otm_name +'</b></div>');
}
else {
/*OTM static display*/
console.log("Static");
for (index = 0, len = otmplace.settings.otms.length; index < len; index = index + 1) {
$('div#OTM').append(
'<div style="text-align:center; float:left; margin:5px;"><a href="'+
otmplace.settings.otms[index].character_link + '">' + otmplace.settings.otms[index].character_name + '</a><br> <img src="' + otmplace.settings.otms[index].character_avatar + '" title="' + otmplace.settings.otms[index].character_name +'" style="width: '+ otmplace.settings.avatar_width +'px; height: auto;"><br><b> ' + otmplace.settings.otms[index].otm_name + '</b></div>' );
}
}
});
|
|
inherit
162752
0
Nov 7, 2024 3:58:23 GMT -8
Pebble
Where it all does or doesn't happen!
1,437
January 2011
pebbleleague
|
Post by Pebble on Jun 27, 2014 4:05:23 GMT -8
Check your spelling of the value for Random and if it has capital letters... That's an easy one to miss.
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jun 27, 2014 4:14:04 GMT -8
Yeah, probably something simple you have overlooked, because I ran this in the console, and it's fine...
var otmplace = pb.plugin.get('placeable_otm');
if(otmplace.settings.random_or_static === "random"){ var ran = (Math.random() * otmplace.settings.otms.length) | 0;
console.log("Random: " + ran); } else { console.log("static"); }
|
|
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 Jun 27, 2014 5:07:07 GMT -8
I think its something odder then that because even viewing source its showing
settings: {"random_or_static":"static","avatar_width":"150","otms":[{"otm_name":"Member Of the Month","character_name":"Admin","character_link":"http://shieldrp.com/user/1","character_avatar":"http://blogs.coventrytelegraph.net/thegeekfiles/shield-logo-marvel-movies.jpg"},{"otm_name":"Discomfort of the Month","character_name":"Glare face","character_link":"http://abstractive.freeforums.net/user/1","character_avatar":"http://31.media.tumblr.com/a0d68524a4161fad66443bc43d04b5a8/tumblr_n7qwxaKBed1qajc4eo1_400.jpg"}
and I've adjusted to use capitals or not and its just not hooking onto Random
|
|
inherit
162752
0
Nov 7, 2024 3:58:23 GMT -8
Pebble
Where it all does or doesn't happen!
1,437
January 2011
pebbleleague
|
Post by Pebble on Jun 27, 2014 5:15:26 GMT -8
But doesn't that show you have it set to static?
|
|