Page 1 of 1

recall the result from ProcedureReturn

Posted: Sat Sep 09, 2023 3:24 pm
by Realizimo
is this a god idea

Code: Select all

Procedure test()
  ProcedureReturn 1  
EndProcedure
If test(): a=getp(): Debug a: EndIf ; getp()=recall the result from ProcedureReturn

Re: recall the result from ProcedureReturn

Posted: Sat Sep 09, 2023 3:37 pm
by Caronte3D

Code: Select all

Procedure test()
  ProcedureReturn 1  
EndProcedure
a=test()
If a: Debug a: EndIf

Re: recall the result from ProcedureReturn

Posted: Sat Sep 09, 2023 4:01 pm
by Realizimo
of course i know that, Caronte3D, this is not a good idea or?

Re: recall the result from ProcedureReturn

Posted: Sat Sep 09, 2023 4:32 pm
by jacdelad
I don't think that's a good idea, too. Storing into a variable is easy and your proposed function would have to handle different data types. Also it gets more and more complicated when using threads (which don't return anything, but can calls functions which return values) and such.

Re: recall the result from ProcedureReturn

Posted: Sat Sep 09, 2023 4:42 pm
by Realizimo
ok, thanks

Re: recall the result from ProcedureReturn

Posted: Sun Sep 10, 2023 1:32 am
by BarryG
Why would this be a good idea? ProcedureReturn already returns any result, which you can store in a variable or structure. Why would a new command be needed to do the same thing?

Re: recall the result from ProcedureReturn

Posted: Mon Sep 11, 2023 12:47 am
by Quin
Yeah, I must say I'm not sure what you're after. It's possibly a language barrier, but it sounds like what you want to do is store the result of a procedure. We have variables for that. If this is wrong, though, feel free to clarify.

Re: recall the result from ProcedureReturn

Posted: Mon Sep 11, 2023 7:52 am
by AZJIO
As you can see, you can store the results of the last operation performed in a structure, but this will use memory. AutoIt3 at least has "error" and "extended" variables that contain some function execution data as statistics for internal functions that you cannot change to add statistics. Initially, it was unusual for me to determine the operation of a function only by the returned result. But it's not hard to do. The only rule is that these results are valid only until the next function call; after calling another function, these results will determine the state of another function.

Code: Select all

EnableExplicit

Structure ProcedureStatus
  string.s
  integer.i
  error.i
  extended.i
EndStructure

Global g_ProcedureStatus.ProcedureStatus


Procedure.s ReplaceStringAndCount(String$, s = 1, o = 0)
	Protected Count
; 	reset variable values ​​before use
	g_ProcedureStatus\error = 0
	g_ProcedureStatus\extended = 0
	g_ProcedureStatus\integer = 0
	g_ProcedureStatus\string = ""
; 	perform any actions
	Count = CountString(String$, " ")
	String$ = ReplaceString(String$ , " " , "_" , #PB_String_CaseSensitive, s, o)
; 	save the results of the function in the form of statistics, which are declared in the function description
	If Count = 0
		g_ProcedureStatus\error = 1
	EndIf
	g_ProcedureStatus\extended = Count
	g_ProcedureStatus\string = String$
    ProcedureReturn String$
EndProcedure

; After performing the replacement operation, obtain the number of replacements, the error status and,
; taking this into account, take any actions, for example, recognize the operation as unsuccessful
Debug ReplaceStringAndCount("go go go")
Debug g_ProcedureStatus\extended
Debug g_ProcedureStatus\error

Re: recall the result from ProcedureReturn

Posted: Mon Sep 11, 2023 6:15 pm
by Realizimo
Quin
yes it what I want, but , I think nicer/shorter code, but I understand that I am just lazy. sorry

Re: recall the result from ProcedureReturn

Posted: Mon Sep 11, 2023 9:02 pm
by HeX0R
oh, o.k., lazy coder, like me?
I sometimes also need something like that, I typically solve it like this:

Code: Select all

Procedure test(*R.INTEGER)
	*R\i = 1
  ProcedureReturn 1  
EndProcedure
If test(@a)
	Debug a
EndIf

Re: recall the result from ProcedureReturn

Posted: Tue Sep 12, 2023 5:43 pm
by the.weavster
I made a feature request for the walrus operator

So then your example would become:

Code: Select all

Procedure test()
  ProcedureReturn 1  
EndProcedure

If a := test()
    Debug a
EndIf

Re: recall the result from ProcedureReturn

Posted: Sun Sep 24, 2023 10:44 am
by Realizimo
the.weavster
Better than my way :D