Jump to content

My Wherigo is crashing on some android phones


day1976

Recommended Posts

Ok, so I built a pay-anywhere Wherigo based on the card game, Go Fish. All worked well when I tested it, but now its published it isn't working on android devices.

 

I built it using urwigo and basically the problem I think is its using up too much memory.  So, what I do is have 52 variables, called card01 through to card52.  I have a function called shuffle, which picks a random number between 1 and 52, then it checks to see if that number has been allotted before, if it hasn't it allots it to the next variable and recalls the shuffle function until all 52 variables are filled.  If the random number has been allotted already then it doesn't allot it and just recalls the function again.  Obviously the first time it is run (for card01) it allots it straight away, but by the time it is looking for the number to fill spaces 40-52 it has to run the shuffle function numerous times to get a result.  Still, on my iPhone it works in about 2-3 seconds.  But on androids it was failing.

 

So, doing some experimentation I found if I added a 1 second timer inbetween each random number call, it would work on my cheap Samsung A20, even though it took 5-10 minutes to work.  But, I have since found that some of my caching buddies who only have androids (and much better androids than I have), even this doesn't work on their phone, even with increasing the timer to a 2 second interval.

 

So, my question is, is there a way around this?  Does someone have an idea on a more elegant way to come up with a 100% random sample of numbers for my variables card01-card52?

 

 

Link to comment

First I would use a table, instead of 52 different variables.

Then it is easy to first fill the table with the values 1 to 52, en then shuffle the values, so you get a random set.

Shuffle like:

function shuffle(tbl)
  for i = #tbl, 2, -1 do
    local j = math.random(i)
    tbl[i], tbl[j] = tbl[j], tbl[i]
  end
  return tbl
end

(see e.g. https://gist.github.com/Uradamus/10323382 )

  • Upvote 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...