Giving random unique item
  • ldmarkley
    Posts: 8
    Joined: Fri Aug 04, 2017 4:39 pm

    Giving random unique item

    by ldmarkley » Wed Feb 13, 2019 9:52 pm

    I was trying to expand on the give the player a random item so that it would give the player a random unique item. In the game we're working on we have 36 possible items. In each playthrough the player will only get four of those items and they shouldn't repeat. I've attached my Javascript below. I've gone from the code freezing up my ARIS app to just not giving the player an item. Any suggestions?

    Code: Select all

    <head>
    <script type='text/javascript'>
    //The next three lines need to stay in to sync with the API
    var ARIS = {};
    ARIS.ready = function()
    {
      var item_names =
      [
        'SpanHat',
        'SpanShoes',
        'SpanCoat',
        'SpanPants',
      ];
            var i;
            var item_id;
      var itemcount = null;
      var c=0;
      while (itemcount !== 0) {
        if (c++ > 500) {
          console.error("Recursion limit of 500 exceeded!");
          alert("Recursion limit exceeded!");
        }
                    i = Math.floor(Math.random()*item_names.length);
                    item_id = ARIS.cache.idForItemName(item_names[i]);
                    itemcount = ARIS.cache.getItemCount(item_id);
      }
    alert (item_id);       
     ARIS.givePlayerItemCount(item_id,1);
    }
    </script>
    </head>
    <div id='content'>

    Put your text content here!

    </div>
  • ldmarkley
    Posts: 8
    Joined: Fri Aug 04, 2017 4:39 pm

    Re: Giving random unique item

    by ldmarkley » Tue Feb 19, 2019 6:15 pm

    So I gave up on the Javascript finally. In spite of all my debugging attempts I could never figure out what it didn't like. The solution I went with was a sort-of-complicated grouping of scenes and using one randomizing script.
    Oh well.

    Related to the same game was there ever a solution for keeping the map from flashing between plaques? I saw an old post where someone had asked about that but didn't see any solutions.
  • User avatar
    chrish
    Posts: 271
    Joined: Mon Oct 10, 2016 5:45 pm
    Location: Albuquerque, NM
    Contact:

    Re: Giving random unique item

    by chrish » Thu Feb 21, 2019 9:44 am

    Sorry for the delay in getting to this. I have a couple ideas but not a ton of help maybe.

    There's not a way to debug right in ARIS though you could set up a page to run from Safari and debug there in the web browser. That might not help if the code you're running through ARIS is specific to ARIS. I bet a few teams have had to do something like that, and hopefully can weigh in on the forums. My guess: they start with the Xcode project for ARIS and run it in the simulator, using the debug tools there. For regular Safari, there is a debug menu you can turn on in the Safari settings but I don't know if it applies to web views within apps.

    As far as the problem of handing out unique items, to make sure no team gets the same one, the easiest way I can think is to do it with physical tokens rather than Javascript. Just have a few physical cards with different QR codes (or something fancier), and have them handed out to different teams at the start.

    Or you could hand them out in order, not randomly, and increment a "world item" to know which one to hand out at any given time. To be a bit more specific:
    item: counter. World starts with 0.
    Set up a dictionary so that each item you want to give out is indexed with a value for counter.
    Every time a team plays, you hand out the corresponding item and then give one counter to the world.
    Making the counter a modular number, or something similar, would make it so you don't need to reset it.
  • User avatar
    chrish
    Posts: 271
    Joined: Mon Oct 10, 2016 5:45 pm
    Location: Albuquerque, NM
    Contact:

    Re: Giving random unique item

    by chrish » Thu Feb 21, 2019 9:46 am

    For the map flashing, it might depend on how you're sending the player. Do you have one plaque whose continue button sends the player to the new plaque?