Jump to content
Sign in to follow this  
niubbone

Function returning always empty strings

Recommended Posts

niubbone

Sorry to post again, but I don't get why i have this problem and honestly i didn't even know what to search in the forum. I looked a few posts but no helpful posts found.

I made this function for a little game I am making.

This function is based on 2 arrays:

Dim $IncidenteLieve[5]

Dim $IncidenteGrave[5]

which should contain some accidents which could randomly happen during the game, The accidents are now shortened in 2g,4g,2l and so on, The blank spaces means you will not have any accident.

The function works like this. A first random number generator generate a number between 1 and 3.

If number is 1 a Light accident may happen. A random number generator pick a number and if this number corresponds to a blank string, you won't have any accident, but if you get a non empty string you will get into that accident (example 2l correspond to a accident, "" is any accident)

If number is 2 it's the same as 1 but with a grevious accident.

If number is 3 you get away with nothing.

At the end i added a while loop to test in about 20 draws, how much the randomness is. So i may get a msgbox wit 2l, some empty ones and so.

But it always returns an empty msgbox, like the string returned is always empty.... Why?

Here's the code: (I shortened a lot arrays which would contain more than 50 accidents each)

Dim $IncidenteLieve[5]
Dim $IncidenteGrave[5]
Dim $IncidenteScelto=""
$IncidenteGrave[0]=""
$IncidenteGrave[1]="2g"
$IncidenteGrave[2]=""
$IncidenteGrave[3]="4g"
$IncidenteGrave[4]="5g"
$IncidenteLieve[0]=""
$IncidenteLieve[1]="2l"
$IncidenteLieve[2]=""
$IncidenteLieve[3]="4l"
$IncidenteLieve[4]="5l"
Func EventSelector()
    Local $SeIncidente = Random(1, 3, 1)
    Select
        Case $SeIncidente = 1
            Local $SelettoreIncidLieve = Random(0, 5, 1)
            If $IncidenteLieve[$SelettoreIncidLieve]=False Then
                Return $IncidenteScelto
            Else
                Return $IncidenteScelto=$IncidenteLieve[$SelettoreIncidLieve]
            EndIf
        Case $SeIncidente = 2
            Local $SelettoreIncidGrave = Random(0, 5, 1)
            If $IncidenteGrave[$SelettoreIncidGrave]=False Then
                Return $IncidenteScelto
            Else
                Return $IncidenteScelto=$IncidenteGrave[$SelettoreIncidGrave]
            EndIf
        Case $SeIncidente = 3
            Return $IncidenteScelto
    EndSelect
EndFunc
For $z=1 to 20
MsgBox(0,"Incidente",$IncidenteScelto)
Next
Exit

To verify if the string it's empty I put If $z[x]=False Then, But also putting If $z[x]="" it's useless....

Why this?

Other question. Is the code fine for you? Would you had written different/better?

Thanks

Share this post


Link to post
Share on other sites
jchd

Equivalent code:

Global $IncidenteLieve[5] = ["", "2l", "", "4l", "5l"]
Global $IncidenteGrave[5] = ["", "2g", "", "4g", "5g"]

Func EventSelector()
    Switch Random(1, 3, 1)
    Case 1
    Return $IncidenteLieve[Random(0, UBound($IncidenteLieve) - 1, 1)]
    Case 2
            Return $IncidenteGrave[Random(0, UBound($IncidenteGrave) - 1, 1)]
    Case 3
            Return ""
    EndSwitch
EndFunc

For $z = 1 To 20
    MsgBox(0, "Incidente", EventSelector())
Next

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
niubbone

Well... Impressive :idea:

Thanks....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.