+day1976 Posted September 18, 2019 Share Posted September 18, 2019 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? Quote Link to comment
+Vooruit! Posted September 18, 2019 Share Posted September 18, 2019 Can you post your code? Quote Link to comment
+Kalkendotters Posted September 18, 2019 Share Posted September 18, 2019 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 ) 1 Quote Link to comment
+day1976 Posted September 19, 2019 Author Share Posted September 19, 2019 Ok, but how does that work in urwigo? Quote Link to comment
Recommended Posts
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.