PlaceholderAPI JavaScript doesn't work.

Discussion in 'Bukkit Help' started by Technohelper, Jan 22, 2019.

Thread Status:
Not open for further replies.
  1. Hello there,

    I have been trying to figure this one out for ages. However I just can't find a solution to this. When I type the Placeholder %javascript_randomintbetween% (Custom JavaScript) it just doesn't work. I have installed the Expansion.
    Here is the line of code:
    Code:
    var min = 999999;
    var max = 9999999;
    
    function randomInteger() {
       if (args.length == 2) {
           min = args[999999];
           max = args[9999999];
       }
    
       var random = Math.random() * (max - min);
           random += min;
    
       return Math.floor(random);
    }
    
    randomInteger();
    I'm sorry, I am kinda new to JavaScript, so sorry if I messed something up. Please leave a fix down below. I have put the spaces in, it's just that this Forum doesn't show them.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Technohelper Did you also put the file in the javascript_placeholders.yml?
     
  3. @timtower Yes, I did everything as the manual said.
     
  4. Offline

    timtower Administrator Administrator Moderator

    Did you contact the developer about it?
     
  5. They told me that the String Size of 2 doesn't fit with the Index 999999
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Technohelper Ahh, now I see it.
    The javascript itself is broken, why do you have 99999 ?
    Because that is argument 99999, not the number.
     
  7. I wanted to make a random number generator between 999,999 and 9,999,999
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Technohelper Then try this:
    Code:
    var min = 999999;
    var max = 9999999;
    
    function randomInteger() {
       if (args.length == 2) {
           min = args[0];
           max = args[1];
       }
    
       var random = Math.random() * (max - min);
           random += min;
    
       return Math.floor(random);
    }
    
    randomInteger();
     
  9. @timtower It just shoes %javascript_randomintbetween%
     
  10. Offline

    timtower Administrator Administrator Moderator

    But is it giving errors?
     
  11. No errors, just %javascript_randomintbetween%
     
Thread Status:
Not open for further replies.

Share This Page