Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 12-May-2014 14:53:00

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

question about return values of a function

is the return value of a function always the last data type before the function ends with ";;"

for example:

  fun drawBitmap(text, wsize, tsize, widget)=
  let wsize -> [texWidth texHeight] in
  let tsize -> [tw th] in
  let _FILLbitmap (_CRbitmap _channel texWidth texHeight) 0xffffff -> bmpRgb in
  let _FILLbitmap8 (_CRbitmap8 _channel texWidth texHeight) 0x00 -> bmp8 in
  //open let fillbitmap8 
  (

    if bmpRgb==nil then
    //open bmprgb  if then else
    	(
    	_fooS "there is no rgb bitmap";
    	 _ADDcompText ongoing_chat_textfield  "there is no rgb bitmap" hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
	  _PAINTcontainer hacker_window_object_container;
		0;
   	 )
     else if bmp8 == nil then
    	(
		_fooS "there is no bitmap mask";
		 _ADDcompText ongoing_chat_textfield  "there is no bitmap mask" hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
	  _PAINTcontainer hacker_window_object_container;
	  0;
    	)
		else if  widget == nil then
    	(
    	 _ADDcompText ongoing_chat_textfield  "no widget passed to bitmap" hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
	  _PAINTcontainer hacker_window_object_container;
		_fooS "no widget passed to bitmap";
    	0;
   	 )
        else
    //open else
    	(
    		let _CRalphaBitmap _channel bmpRgb bmp8 nil nil -> abmp in
			//open abmp let
			(    	
    				if abmp == nil then
    				//open abmp if then else
    					(
    						_fooS "there is no abmp, in other words, no alpha bitmap";
    						_ADDcompText ongoing_chat_textfield  "there is no abmp, in other words, no alpha bitmap" hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
							_PAINTcontainer hacker_window_object_container;
	  						0;	
    					)			
    					else
    					//open else
    					(
    						_fooS "there is a bmprgb bitmap, there is a bmp8 bitmap, and there is a local varaible abmp that contains an alphabitmap";
    						_ADDcompText ongoing_chat_textfield  "there is a bmprgb bitmap, there is a bmp8 bitmap, and there is a local varaible abmp that contains an alphabitmap" hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
							_PAINTcontainer hacker_window_object_container;
    						
 	   					let _GETalphaBitmaps abmp -> [rgb alpha] in
   						//open GETalphaBitmaps let
   			 				(
      								_DRAWtext rgb hacker_font (texWidth / 2) (texHeight / 2) - (th / 2) TD_CENTER 0xffffff text;
      								_DRAWtext8 alpha hacker_font (texWidth / 2) (texHeight / 2) - (th / 2) TD_CENTER 0xffffff text;
      								if ((SO3BitmapWidgetBlitAlpha widget abmp) == nil) then
      								//open blit if then else
      											(			
    													_fooS  "failed to blitmap";
    													_ADDcompText ongoing_chat_textfield  strcatn "\n"::"failed to blitmap to widget"::nil hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
														_PAINTcontainer hacker_window_object_container;							
    													0;
      											)
      								else
      											(
      			   								_fooS "bltmap succeeded, do you see one?";
      			   								_ADDcompText ongoing_chat_textfield  strcatn "\n"::"created blitmap to widget"::nil hacker_font [0x00FFFF 0 0 0xFFFF00] CT_END; 
														_PAINTcontainer hacker_window_object_container;	
      			   								0;
      								//close blit if then else
      											);
    							//close GETalphaBitmaps let
    							);
    
								 //bitmaps copied in alpha bitmap so we can destroy them
    							_DSbitmap bmpRgb;
    							_DSbitmap8 bmp8;
    						//close else
    						0;
    						);
    					//close abmp let
    					0;
    				);
    					
   // close bmprgb  if then else
	75;	  
	);

Would this function return the integer 75?

Offline

#2 12-May-2014 17:09:10

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: question about return values of a function

yes

Offline

#3 12-May-2014 17:13:37

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: question about return values of a function

arkeon wrote:

yes

thx arkeon, I will figure out where this widget script is not working.

Offline

#4 12-May-2014 17:20:45

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: question about return values of a function

Yes, the function returns the return value of the last statement.

fun foobar (a)=
	_fooS "The function name is 'foobar'";	// a statement, ended by ;
	a;;	// another statement

foobar returns 'a' (the value of a) because this is the last statement.

fun calcul (a, b)=
	if a < b then
		b-a	// the last statement if a < b
	else
		a-b;;	// the last statement if a >= b
		
fun calcul2 (a, b)=
	if a < b then
		b-a
	else
		a-b;
	75;;	// always the last statement, so 'calcul2' always returns '75'
	
fun calcul3 (a, b)=
	if a == b then
		nil	// the last statement if a == b
	else
		calcul a b;;	// the last statement if a != b and returns the return value of the called function
	
fun main ()=
	_showconsole;
	
	_fooId calcul 10 3;	// display '7'
	_fooId calcul 4 12;	// display '8'

	_fooId calcul2 10 3;	// display '75'
	_fooId calcul2 4 12;	// display '75'

	_fooId calcul3 10 3;	// display '7'
	_fooId calcul3 4 4;	// display 'NIL'

	0;;

Offline

#5 12-May-2014 17:28:49

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: question about return values of a function

Your drawBitmap function returns a wrong value ?
What type of value want you return ?

Offline

#6 12-May-2014 17:55:46

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: question about return values of a function

iri wrote:

Your drawBitmap function returns a wrong value ?
What type of value want you return ?

I'm not sure yet, it's just a question I had.

Offline

Board footer

Powered by FluxBB