123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|522|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Handheld Coding -> Randomly distributed coordinates...

Thu, 16 May 2013, 14:51
Afr0
So, I got myself an iPad on a whim.
Since we're currently tantalizingly close to the first milestone on Project Dollhouse, and I'm basically just waiting for the other developer to implement the client changes, I decided to start a very simple project for the iPad.
Took me a while to settle on the language to use, but eventually I decided on haXe.
Unlike Monkey, it is free, and allows me the option to target multiple platforms.
Anyway...

For the simple quiz engine I'm developing (allows you to load different types of questions from question files), I need to randomly distribute coordinates for answers.

Currently I have:



This works fine (notice the awesomeness that is haXe, btw - XML nodes are evaluated at runtime!), but means that the right answer will always be at the top! This is an unacceptable condition.

I realize that I could hardcode a bunch of coordinates for different resolutions, and then randomly select between them. But this would either limit the number of answers, or force me to hardcode something like 20 coordinates.
There has to be a more elegant way to do this?!

Ideas, plxz!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 16 May 2013, 15:12
Jayenkai
1. Don't randomise the co-ords. Instead, randomise the answers..
If you start with ...
Which is Better?|This|That|The Other
Dump it into a set of variables
Question$="Which is Better?"
Ans$[1]="This"
Etc,etc.

Then do a shuffler, to randomise the Ans$, remembering of course to keep track of which one's the correct answer.

For n=1 to MostAnswers
Random=rand(1,MostAnswers)
Temp$=ans$[n]
Ans$[n]=Ans$[Random]
Ans$[Random]=Temp$
Next

Then you can simply print out question and answers.

As for where they appear, simple maths should suffice. You're not randomising the locations, you're now instead placing text in a preset order.

You CAN now either do it using preset variables, or, instead, work out the available space, divide by number of answers, work out central position, and locate from there.
Simple maths.

.. And as a gripe. I tried HaXe, but disliked the need for multiple files to achieve simple tasks. I'm more comfortable having a 20,000 line chaotic spaghetti file, than trying to remember which of my 78 files contained the code to let the player enter their name during the Titlescreen.

-=-=-
''Load, Next List!''
Fri, 17 May 2013, 01:20
Afr0
Thanks for that brilliant solution!
Yet again, an example of how I tend to overthink problems (or, to be more specific: the solutions).

As for your gripe, you are supposed to use an IDE to do that. Actually, you could do that with one file as well, if you had a proper IDE. I bet the Monkey IDE doesn't allow you to right click a type or function and go to its definition or declaration.
The one thing I don't like about haXe is that it forces you to put files into directories if they are in separate packages (read: namespaces), and packages MUST be written in all lower space characters. A compiler shouldn't force those sort of restrictions!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!