Arrays: Selecting data at random

Started by dangerousbrian, July 31, 2005, 10:28:46 AM

Previous topic - Next topic

dangerousbrian

I'm working on a word game now...  I need to  take a string & store each letter which the below code does quite nicely. (Just storing the ASC codes in case I find I need them)
   
s$="OLDENBURG HOTEL"
 ans=Len(s$)
 Dim letval(Len(s$)):Dim char$(Len(s$))
 For lp =1 To Len(s$)
    c$=Mid$(s$,lp,1)
    char$(lp)=c$
    letval(lp)= Asc(c$)
    ;Print letval(lp):Print char$(lp)
      Next lp

But now I need to go onto a blank screen & pop the individual letters up (in their right place!) at 10sec intervals for a 'guess the word' game. Can I access an array & take random info out (and on the next pass make sure it doesn't grab a letter thats already been selected & displayed?)
Alternatively I could just scramble the letters & print the new string, but I still need to grab them at random........

dangerousbrian

Draco9898

#1
You mean text that get's put onto the screen slowly? Like on many, many games? Well I almost had it once, but for some reason GetStringWidth() wasn't making the letters go into the correct places

I'll see if I can hack something up later, oh, and intenting your code might prove very useful when trying to read it
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

dangerousbrian

Thanks for your help Draco. If you run the code below you'll see what I'm trying to do. (ignore the print command in the first loop, it was just there so I could see that things were working). When the "??????? ??????" screen comes up I then want to replace, one at a time, at 10sec intervals or on a keypress the ? with a letter.
Don't know what you mean about intenting?

dangerousbrian
OpenScreen 800,600,16,2:Mouse Off
LoadFont "Ariel",2,48,0:SetFont 2
Cls 0
 s$="A STITCH IN TIME SAVES NINE"
 ans=Len(s$)
 Dim letval(Len(s$)):Dim char$(Len(s$))
     Dim qes$(Len(s$))
 For lp =1 To Len(s$)
    c$=Mid$(s$,lp,1)
    char$(lp)=c$
    letval(lp)= Asc(c$)
    Print letval(lp):Print char$(lp)
      Next lp
Sync
WaitKey
Cls 0
qs$=" "
For lp=1 To (Len(s$))
If letval(lp)<>32 Then qes$(lp)="?"
If letval(lp)=32 Then qes$(lp)=" "
qs$=Insert$(qs$,qes$(lp),lp)
Next lp
Text 0,300,qs$
Sync
Wait 2000
WaitKey