#122435 - 2004-07-08 11:21 PM
Creating a UDF function
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
OK first attempt here to make a custom function.
What I am trying to do is populate mutiple lines with random values, and trying to create a function, I recieve no values.
Rays 0, 30, 10, 3.0, 0x00EFEFFF, 1.0
Rays 3, 25, 8, 2.5, 0x00EFEFFF, 1.9
Code:
srnd(@TICKS*@MSECS*2)
random_var($NumPolys,$NumStreaks,$OuterRadius,$InnerOpacity,$OuterOpacity,$ColourTemp)
WriteLine(5, '# Rays D, NumPolys, NumStreaks, OuterRadius, Colour, ColourTemp'+Chr(13))
WriteLine(5, 'Rays '+ $NumPolys + ', '+ $NumStreaks +', '+ $OuterRadius +', '+ $OuterOpacity +', 0x00'+ $KeyColor[$dd] +', '+ $ColourTemp +''+Chr(13))
WriteLine(5, Chr(13))
function random_var($NumPolys,$NumStreaks,$OuterRadius,$InnerOpacity,$OuterOpacity,$ColourTemp)
$dd = 5 * rnd(30)
formatnumber($NumPolys,0.00) = 0.0
$NumPolys = 1.1 * rnd(10)
$NumStreaks = rnd(20)
$OuterRadius = rnd(10)
$InnerOpacity = 1.1 * rnd(10)
$OuterOpacity = 1.1 * rnd(10)
endfunction
Edited by Microcyb (2004-07-08 11:22 PM)
|
|
Top
|
|
|
|
#122437 - 2004-07-09 02:24 AM
Re: Creating a UDF function
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This is closer to being a proper function. It returns an array of values.
$ArrayOfValues = Random_Var()
Code:
for each $value in Random_Var()
? $value
next
function Random_Var()
Dim $NumPolys,
$NumStreaks,
$OuterRadius,
$InnerOpacity,
$OuterOpacity,
$dd
srnd(@TICKS*@MSECS*2)
$dd = 5 * rnd(30)
$NumPolys = formatnumber(1.1 * rnd(10),2)
$NumStreaks = rnd(20)
$OuterRadius = rnd(10)
$InnerOpacity = 1.1 * rnd(10)
$OuterOpacity = 1.1 * rnd(10)
$Random_Var = $NumPolys,$NumStreaks,$OuterRadius,$InnerOpacity,$OuterOpacity
endfunction
Edited by Howard Bullock (2004-07-09 06:04 PM)
|
|
Top
|
|
|
|
#122439 - 2004-07-09 03:31 PM
Re: Creating a UDF function
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
you are close....
Code:
random_var()
WriteLine(5, '# Rays D, NumPolys, NumStreaks, OuterRadius, Colour, ColourTemp'+Chr(13)) WriteLine(5, 'Rays '+ $NumPolys + ', '+ $NumStreaks +', '+ $OuterRadius +', '+ $OuterOpacity +', 0x00'+ $KeyColor[$dd] +', '+ $ColourTemp +''+Chr(13)) WriteLine(5, Chr(13))
function random_var() dim $dd $dd = 5 * rnd(30) formatnumber($NumPolys,0.00) = 0.0 $NumPolys = 1.1 * rnd(10) $NumStreaks = rnd(20) $OuterRadius = rnd(10) $InnerOpacity = 1.1 * rnd(10) $OuterOpacity = 1.1 * rnd(10) endfunction
|
|
Top
|
|
|
|
#122440 - 2004-07-09 04:18 PM
Re: Creating a UDF function
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
Ah thank you. Going to now sit down and make sure I follow the manual and the examples you all gave.
|
|
Top
|
|
|
|
#122442 - 2004-07-09 05:58 PM
Re: Creating a UDF function
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Quote:
Close you say? What about scope? Debatable as a best practice.
I dont understand what you mean.....
looks to me like he has a set number of global variables that he wants to randomize in the fly. a function used in the above method is perfect for that. A function does not always have to return data. It is cheap efficiant use of code.
Bryce
|
|
Top
|
|
|
|
#122444 - 2004-07-12 10:25 AM
Re: Creating a UDF function
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|