Jump to content
Sign in to follow this  

Function returning always empty strings

Recommended Posts

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=""
Func EventSelector()
    Local $SeIncidente = Random(1, 3, 1)
        Case $SeIncidente = 1
            Local $SelettoreIncidLieve = Random(0, 5, 1)
            If $IncidenteLieve[$SelettoreIncidLieve]=False Then
                Return $IncidenteScelto
                Return $IncidenteScelto=$IncidenteLieve[$SelettoreIncidLieve]
        Case $SeIncidente = 2
            Local $SelettoreIncidGrave = Random(0, 5, 1)
            If $IncidenteGrave[$SelettoreIncidGrave]=False Then
                Return $IncidenteScelto
                Return $IncidenteScelto=$IncidenteGrave[$SelettoreIncidGrave]
        Case $SeIncidente = 3
            Return $IncidenteScelto
For $z=1 to 20

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?


Share this post

Link to post
Share on other sites

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 ""

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

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...