Jump to content

Create Function Question


Recommended Posts

Hi,

i want to know something about creating a function.

How do i write the function when i want that

2 paramaters need to be given and for example 1 parameter may be given.

Like in Random( min, max [, flat ] )

How do i write my first line for func then?

Func _Random( $min, $max [, $flat ] )
Random( $min, $max )
EndFunc

This code made an error appear

regards Daniel

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

HI,

what about

Func ran($min, $max, $bla = 1)
...

EndFunc

Or do you mean how to call the func?

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks very much :)

Did i said before that this forum rocks very hard ? :(

Like a france guy would say now

Msgbox(0, "", "Luv u all !", 5)

Thanks again ^^

€: Yet another question ....

I have this code

Dim $min
Dim $max
Dim $leave1, $leave2, $leave3, $leave4, $k, $i
For $h = 1 to 5 Step 1
$k = _Random( 1, 5, 1, 2, 3, 4)
MsgBox(0, "", $k)
Next

Func _Random( $min, $max , $leave1, $leave2, $leave3, $leave4)
        $i = Random( $min, $max, 1)
        While $i = $leave1 
            $i = Random( $min, $max, 1)
        WEnd
        While $i = $leave2
            $i = Random( $min, $max, 1)
        WEnd
        While $i = $leave3 
            $i = Random( $min, $max, 1)
        WEnd
        While $i = $leave4 
            $i = Random( $min, $max, 1)
        WEnd
    Return $i
EndFunc

Now it should give out 5 times a msgbox with "5" but it doesnt and i dont know why.

Edited by Daniel W.

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

  • Moderators

Thanks very much :)

Did i said before that this forum rocks very hard ? :(

Like a france guy would say now

Msgbox(0, "", "Luv u all !", 5)

Thanks again ^^

: Yet another question ....

I have this code

Dim $min
Dim $max
Dim $leave1, $leave2, $leave3, $leave4, $k, $i
For $h = 1 to 5 Step 1
$k = _Random( 1, 5, 1, 2, 3, 4)
MsgBox(0, "", $k)
Next

Func _Random( $min, $max , $leave1, $leave2, $leave3, $leave4)
        $i = Random( $min, $max, 1)
        While $i = $leave1 
            $i = Random( $min, $max, 1)
        WEnd
        While $i = $leave2
            $i = Random( $min, $max, 1)
        WEnd
        While $i = $leave3 
            $i = Random( $min, $max, 1)
        WEnd
        While $i = $leave4 
            $i = Random( $min, $max, 1)
        WEnd
    Return $i
EndFunc

Now it should give out 5 times a msgbox with "5" but it doesnt and i dont know why.

Kind of answered this in your last thread
;Don't need to dim values in the Function
For $h = 1 to 5 Step 1
    $k = _Random( 1, 5, 1, 2, 3, 4)
    MsgBox(0, "", $k)
Next

Func _Random( $min, $max , $leave1, $leave2, $leave3, $leave4)
        Do
            $i = Random( $min, $max, 1)
        Until $i <> $leave1 And $i <> $leave2 And $i <> $leave3 And $i <> $leave4
    Return $i
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

KK i got the little error in my "solution" that i wrote Until $i = $leave1 or $leave2 etc before ....

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
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
 Share

  • Recently Browsing   0 members

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