Jump to content

Recommended Posts

Posted

Can a Multidimensional array be with different sizes? It's possible to declare them?

Like this:

$s[1][2]=[1,2]
$s[2][3]=[3,4,5]

instead of the usual $s[2][3] with 2 rows of 3 elements?

Posted

Your syntax is wrong...

$s[2][3] = [[1,2],[3,4,5]]

// then you can redim it like this

redim $s[2][2]

Pist...Use a declaration keyword to declare an array else you may get a syntax error. :mellow:
Posted

niubbone, you can only have one size at any given time , though you can redim it to fit more or less elements. However, if you absolutely need to have varying dimensions, you can put arrays inside an array, though you have to ask yourself if its worth it or if you can think of a better way.

Posted (edited)

Thanks to all. Well, the redim may be what i was looking for. Don't worry about all the syntax errors, I know them and by the way the error check won't let me run the script if there are any :mellow: It was just to make the situation more clear.

Anyway, I need that 2d array because of this function (which I still need to work because it's not working properly):

#include <array.au3>
$Multi=ColloquioDomande()
_ArrayDisplay($Multi,"PORCO")
Func ColloquioDomande()
    Local $Domande[5]=["doma","domb","domc","domd","dome"]
    Local $Risposte[20]=["a","b","c","d","a1","b1","c1","d1","a2","b2","c2","d2","a3","b3","c3","d3","a4","b4","c4","d4"]
    Local $DomandeDifferenti[4]
    Local $RisposteMischiate[4]
    For $z=1 to 4
        Local $GiroDomande=Random(1,Ubound($Domande)-1,1)
        $DomandeDifferenti[$z-1]=$Domande[$GiroDomande]
        _ArrayDelete($Domande,$GiroDomande)
        Select
            Case $GiroDomande=0
                Local $Risp1=$Risposte[0],$Risp2=$Risposte[1],$Risp3=$Risposte[2],$Risp4=$Risposte[3]
            Case $GiroDomande=1
                Local $Risp1=$Risposte[4],$Risp2=$Risposte[5],$Risp3=$Risposte[6],$Risp4=$Risposte[7]
            Case $GiroDomande=2
                Local $Risp1=$Risposte[8],$Risp2=$Risposte[9],$Risp3=$Risposte[10],$Risp4=$Risposte[11]
            Case $GiroDomande=3
                Local $Risp1=$Risposte[12],$Risp2=$Risposte[13],$Risp3=$Risposte[14],$Risp4=$Risposte[15]
            Case $GiroDomande=4
                Local $Risp1=$Risposte[16],$Risp2=$Risposte[17],$Risp3=$Risposte[18],$Risp4=$Risposte[19]
        EndSelect
        Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
        For $i=1 to 4
            Local $GiroRispInOrdine=Random(1,Ubound($RisposteInOrdine)-1,1)
            $RisposteMischiate[$i-1]=$RisposteInOrdine[$GiroRispInOrdine]
            _ArrayDelete($RisposteInOrdine,$GiroRispInOrdine)
        Next
    Next
    Local $MultiDomERisp[2][16]=[[$DomandeDifferenti[0],$DomandeDifferenti[1],$DomandeDifferenti[2],$DomandeDifferenti[3]], _
    [$RisposteMischiate[0],$RisposteMischiate[1],$RisposteMischiate[2],$RisposteMischiate[3]]]
    Return $MultiDomERisp
EndFunc

Quick Explanation: This program should extract from 2 arrays given a question and 4 answers for each question, always checking that the previous question and answer have not been already extracted amd, to scramble the answers everytime to put them in a different order. Questions are $Domande and answers are $Risposte. The results are given into 2 arrays which, as far as i know, cannot be returned with a single Return

at the end of the functionm therefore i have to store them in a multidimensional array and make a return whichi gives the multidimensional array as result of the function.

That's why i need it. But if you know a better solution i'm all ears.

Thanks :P

Edited by niubbone

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...