Creating a scrambled list

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Creating a scrambled list

Postby reneuend » Tue Dec 10, 2013 4:05 am

I'm building a game where there is a quiz containing 10 questions. In order to make it more versatile. I choose the 10 questions from a total of 20 questions, randomly. This way when the user retakes the test the same questions may or may not on the quiz.

There are many other uses for scrambling numbers, etc. I think the most compelling reason is to make a game more interesting when its replayed, as the random values can be used to mix the game up a bit.

Issue: AdventureMaker doesn't have global arrays.
Solution: Actually, I came up with my own solution a few years ago by creating functions that work with delimited lists. So, instead of storing values in an array, I store them in a delimited list.
Ex.
aArray(0) = "This" aArray(1) = "Is" aArray(2) = "An" aArray(3) = "Array"
sDelimitedString = "This,Is,A,Delimited,String"

As long as you have functions that work with a delimited string, you can do everything with delimited strings that you can with arrays. The plus is that the string is a variant and can be used globally.


Now for fun:

Create a test frame and add the following to your advanced frame properties:


Code: Select all
cnt = 0
scrambledlist = ""

do Until cnt >= 10
  val = randomInt(1,10)
  If FindWord(val, scrambledlist, ",") < 0 Then
    scrambledlist = scrambledlist & val & ","
    cnt = cnt + 1
  End If
Loop

scrambledlist = Left(scrambledlist, Len(scrambledlist)-1)

msgbox scrambledlist




Before you run it, add the following to your procedures area.
NOTE: You should save a copy of these procedures for future use. I will show other tutorials on how to use them in other situations in the future.


Code: Select all
Function FindWord(word, text, delimiter)
  sNeedle = word
  FindWord = -1
  aHaystack = Split(text, delimiter)
  for x = 0 to UBound(aHayStack) - 1
    If cint(aHayStack(x)) = cint(sNeedle) Then
      FindWord = x
      Exit For
    End If
  Next

End Function


Code: Select all
Function RandomInt(lower,upper)
  Randomize
  RandomInt = int(rnd*(upper-lower+1))+lower
End Function 'RandomInt


Code: Select all
Function GetWord(index,text,delimiter)

Dim aWords

If ltrim(text) = "" Then
   GetWord = ""
   Exit Function
End If

If index > 0 Then
  index = index - 1
Else
  GetWord = ""
  Exit Function
End If

aWords = Split(text, delimiter)


If ubound(aWords) < index Then
  GetWord = ""
  Exit Function
End If

GetWord = ltrim(aWords(index))

End Function
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Creating a scrambled list

Postby Simon » Tue Dec 10, 2013 12:39 pm

That's interesting Bob ! You probably know that in ASA there is a quiz of 20 questions, but they are always the same. I wish I could have found a way to make them random. Maybe in a next game ? 8)

Don't you think it would be easier to create an external .INI file for that kind of game ? The INI file could contain your full list of 20 questions. Then the action ReadINI would be interesting to pick them in the game. Usually, the lines in the INI file are marked with an index number if I remember well.
Read the .INI file using returnvalue=Action.ReadINI(filename+".save",index,row)

Maybe you could call a list of 10 different random numbers to pick the questions in the INI ?
I find it interesting because the INI can be easily edited with notepad, so you can add and remove questions from the full list without loading the project in AM.
User avatar
Simon
Expert Member
 
Posts: 418
Joined: Sun Jun 10, 2012 1:47 pm
Location: France

Re: Creating a scrambled list

Postby reneuend » Tue Dec 10, 2013 10:46 pm

The INI file would be a good way to hold values, but it can't randomize the values. In the case of a quiz, I would store the questions and answers there, but then use the code I've shown here to randomize what questions/answers would be shown.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron