Jump to content
Sign in to follow this  
Vindicator209

Return as an Array

Recommended Posts

Vindicator209

How do I return something as a 2 part array? Like MouseGetPos()

I'm making a Function ( in a separate script ) but when the other script declares a variable, it's not picked up in my main script. I I suppose Returning is the only way.


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
Vindicator209

ooh, and another thing, how do I close GUI's from other scripts? I've tried exit loop and GuiDelete, but they still stand =P

Func LoginBox($lTitle,$lText,$lUsernameDefault,$lPasswordDefault,$BlockPassword,$lX,$lY)

$lForm1 = GUICreate($lTitle, 297, 190, 193, 115)
If $BlockPassword = 1 Then
$lInput1 = GUICtrlCreateInput($lPasswordDefault, 8, 136, 281, 21, $ES_PASSWORD)
Else
$lInput1 = GUICtrlCreateInput($lPasswordDefault, 8, 136, 281, 21)
EndIf
$lInput2 = GUICtrlCreateInput($lUsernameDefault, 8, 112, 281, 21)
$lLabel1 = GUICtrlCreateLabel($lText, 8, 8, 283, 97)
$lButton = GUICtrlCreateButton("Ok", 8, 160, 281,21)
GUISetState(@SW_SHOW)

While 1
    $lMsg = GUIGetMsg()
    Switch $lMsg
        Case $lButton
            $lUser=GUICtrlRead($lInput2)
            $lPass=GUICtrlRead($lInput1)
            ExitLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
EndFunc

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
Achilles

How do I return something as a 2 part array? Like MouseGetPos()

I'm making a Function ( in a separate script ) but when the other script declares a variable, it's not picked up in my main script. I I suppose Returning is the only way.

#include <Array.au3>

$returnedArray = _ReturnArray()
_ArrayDisplay($returnedArray, '_ReturnArray')

Sleep(100)


Func _ReturnArray()
    Dim $array[3] = ['1','2','3']
    Return $array
EndFunc
Does this help?

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
Vindicator209

Now how does this work?

Heres what I tried:

Func LoginBox($lTitle,$lText,$lUsernameDefault,$lPasswordDefault,$BlockPassword,$lX,$lY)

$lForm1 = GUICreate($lTitle, 297, 190, 193, 115)
If $BlockPassword = 1 Then
$lInput1 = GUICtrlCreateInput($lPasswordDefault, 8, 136, 281, 21, $ES_PASSWORD)
Else
$lInput1 = GUICtrlCreateInput($lPasswordDefault, 8, 136, 281, 21)
EndIf
$lInput2 = GUICtrlCreateInput($lUsernameDefault, 8, 112, 281, 21)
$lLabel1 = GUICtrlCreateLabel($lText, 8, 8, 283, 97)
$lButton = GUICtrlCreateButton("Ok", 8, 160, 281,21)
GUISetState(@SW_SHOW)

While 1
    $lMsg = GUIGetMsg()
    Switch $lMsg
        Case $lButton
            _ReturnArray(GUICtrlRead($lInput2),GUICtrlRead($lInput1))
            ExitLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
EndFunc

Func _ReturnArray($lUser,$lPass)
    Dim $array[2] = [$lUser,$lPass]
    Return $array
EndFunc

It returned "0"


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
smashly

A working bit of code would be good to start with, so I improvised with your code.

Excuse the changes, but this should give you the idea of why it returns 0 the way your using it.

#include <GuiConstants.au3>
$lForm1 = GUICreate('whatever' , 297, 190, 193, 115)
$lInput1 = GUICtrlCreateInput('whatever', 8, 136, 281, 21, $ES_PASSWORD)
$lInput1 = GUICtrlCreateInput('whatever1', 8, 136, 281, 21)
$lInput2 = GUICtrlCreateInput('whatever2', 8, 112, 281, 21)
$lLabel1 = GUICtrlCreateLabel('whatever', 8, 8, 283, 97)
$lButton = GUICtrlCreateButton("Ok", 8, 160, 281,21)
GUISetState(@SW_SHOW)

While 1
    $lMsg = GUIGetMsg()
    Switch $lMsg
        Case $lButton
            $aReturn = _ReturnArray(GUICtrlRead($lInput2),GUICtrlRead($lInput1))
                MsgBox(0,'$array returns', '$array[0] = ' & $aReturn[0] & @LF & '$array[1] = ' & $aReturn[1])
            ExitLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _ReturnArray($lUser,$lPass)
    Dim $array[2] = [$lUser,$lPass]
    Return $array
EndFunc

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites
Vindicator209

now it works iin script itself, but when its "included" it returns 0... am I missing something?

#include <PopupBox.au3>
$log=LoginBox("text","test","test","test",1,-1,-1)
MsgBox(0,"",$log)

EDIT (without editing, lol): Never mind, I got it, thanks all..

though still, the questoin remains, how do I close these darn windows??

Ok Ive tried the folowing to close them:

GuiDelete

WinClose

WinKill

ExitLoop

but none of them will shut it down!!! rawr =.=

Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
Valuater

Remeber ... it returns an Array

#include <PopupBox.au3>
$log=LoginBox("text","test","test","test",1,-1,-1)
MsgBox(0,$log[0], $log[1])

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
smashly

Hi,

Instead of posting snippets of code that leave onlookers wondering what a variable is equal to or isn't declared..etc

How about posting the actual whole code, then maybe we can get a better idea to be more helpful towards your cause.

Cheers

Share this post


Link to post
Share on other sites
Vindicator209

:)

#include <GUIConstants.au3>

Func ComboBox($cTitle,$cText,$cComboName,$cX,$cY)
$cForm=GUICreate($cTitle, 193, 167, $cX, $cY)
$cCombo = GUICtrlCreateCombo($cComboName, 10, 136, 140, 25)
$cButton = GUICtrlCreateButton("OK", 150, 136, 30, 25)
GUICtrlCreateLabel($cText, 10, 10, 169, 121)
GUISetState(@SW_SHOW)
$i=0
For $sArrayElement In $ComboAdd
    GUICtrlSetData($cCombo, $sArrayElement, GUICtrlRead($cCombo))
Next
While 1
    $cMsg = GUIGetMsg()
    Switch $cMsg
        Case $cButton
            Return(GUICtrlRead($cCombo))
            WinKill($cTitle)
            ExitLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
EndFunc

Func LoginBox($lTitle,$lText,$lUsernameDefault,$lPasswordDefault,$BlockPassword,$lX,$lY)

$lForm1 = GUICreate($lTitle, 297, 190, 193, 115)
If $BlockPassword = 1 Then
$lInput1 = GUICtrlCreateInput($lPasswordDefault, 8, 136, 281, 21, $ES_PASSWORD)
Else
$lInput1 = GUICtrlCreateInput($lPasswordDefault, 8, 136, 281, 21)
EndIf
$lInput2 = GUICtrlCreateInput($lUsernameDefault, 8, 112, 281, 21)
$lLabel1 = GUICtrlCreateLabel($lText, 8, 8, 283, 97)
$lButton = GUICtrlCreateButton("Ok", 8, 160, 281,21)
GUISetState(@SW_SHOW)

While 1
    $lMsg = GUIGetMsg()
    Switch $lMsg
        Case $lButton
 _ReturnArray(GUICtrlRead($lInput2),GUICtrlRead($lInput1))
            ExitLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

EndFunc

Func _ReturnArray($lUser,$lPass)
    Dim $array[2] = [$lUser,$lPass]
    Return $array
EndFuncoÝ÷ Ø¥²ay-+¢é]mæ§y«2j[^®v­÷ºØ­v¬mëmë¬z¶¶æ¥(¶Ø^zn¶åË^j׫ٵÈ^²Ø^»ºÚ"µÍ[ÈÙÚ[Þ
    ÌÍÛ]K    ÌÍÛ^ ÌÍÛÙ[YQY][  ÌÍÛÜÝÛÜY][   ÌÍÐØÚÔÜÝÛÜ    ÌÍÛ  ÌÍÛK ÌÍÛÙ    ÌÍÛÜÝÛÜ
BÌÍÛÜLHHÕRPÜX]J   ÌÍÛ]KMËNLNLËLMJBY  ÌÍÐØÚÔÜÝÛÜHH[ÌÍÛ[]HHÕRPÝÜX]R[]
    ÌÍÛÜÝÛÜY][LÍKK  ÌÍÑT×ÔTÔÕÓÔ
B[ÙBÌÍÛ[]HHÕRPÝÜX]R[]
    ÌÍÛÜÝÛÜY][LÍKJB[YÌÍÛ[]HÕRPÝÜX]R[]
    ÌÍÛÙ[YQY][LLKJBÌÍÛX[HHÕRPÝÜX]SX[
    ÌÍÛ^ËMÊBÌÍÛ]ÛHÕRPÝÜX]P]Û   ][ÝÓÚÉ][ÝËMKJBÕRTÙ]Ý]JÕ×ÔÒÕÊBÚ[HBIÌÍÛÙÈHÕRQÙ]ÙÊ
BTÝÚ]Ú   ÌÍÛÙÂBPØÙH   ÌÍÛ]ÛBBRYÕRPÝXY
    ÌÍÛ[]HH  ÌÍÛÙ[BBBRYÕRPÝXY
    ÌÍÛ[]JHH ÌÍÛÜÝÛÜ[BBBBT]YBBBBQ[ÙBBBBBT][ÙBBBBQ[YBBQ[ÙBBBBT][ÙBBBQ[YBBUÚ[Ú[
    ÌÍÛ]JBBBQ^]ÛÜBPØÙH   ÌÍÑÕRWÑUSÐÓÔÑBBBQ^]ÛÜQ[ÝÚ]ÚÑ[[[oÝ÷ Ø  Ý+^²Û®*mjëh×6
#include <PopupBox.au3>
Local $ComboAdd[4]
$ComboAdd[0] = "ONE"
$ComboAdd[1] = "TWO"
$ComboAdd[2] = "1"
$ComboAdd[3] = "2"
$Combo=ComboBox("Test","Hey!","Ok",-1,-1)
MsgBox(0,"",$Combo)
$log=LoginBox("text","test","test","test",1,-1,-1,"Kyle","Moy")
MsgBox(0,"",$log[0]&$log[1])
Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

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  

×