Page 1 of 1

String interpolation

Posted: Sun Mar 18, 2018 11:05 am
by djrikki
Hi Andreas,

I am trying to dramatically reduce lines of code in my program and I would like to know if it is possible to perform string interpolation in Hollywood?

Take the following code which I am attempting to make valid:

Code: Select all

Function base:FuncOnField(id, field, func)
  mui.Set(id, mui.Get(id, field), func(id,field))
EndFunction

base:FuncOnField(msg.id,"contents","LowerStr") ; a typical call might be
base:FuncOnField(msg.id,"contents","UpperStr") ; or
I am trying to avoid the old skool way of doing this...

Code: Select all

Function base:FuncOnField(id, field, func)
   If func = "LowerStr"
      mui.Set(id, mui.Get(id, field), LowerStr(field))
   ElseIf func = "UpperStr"
      mui.Set(id, mui.Get(id, field), UpperStr(field))
   EndIf
EndFunction

Re: String interpolation

Posted: Sun Mar 18, 2018 11:42 am
by djrikki
(OP Edit time elapsed: code corrections)

Attempting to make the following code valid:

Code: Select all

;base:FuncOnField(msg.id,"contents","LowerStr")
Function base:FuncOnField(obj, field, func)
    mui.Set(obj.id, field, func(obj.triggervalue))
EndFunction
I am trying to avoid the verbose old skool way of doing this...

Code: Select all

Function base:FuncOnField(obj, field, func)
	If func = "LowerStr"
	    mui.Set(obj.id, field, LowerStr(obj.triggervalue))
	
	ElseIf func = "UpperStr"
	    mui.Set(obj.id, field, UpperStr(obj.triggervalue))
	EndIf
Endfunction
At the moment I just get the error: Function func() not found!

Re: String interpolation

Posted: Tue Mar 20, 2018 7:34 pm
by airsoftsoftwair
I don't see how this is related to string interpolation but you probably just have to pass the function as a reference, not as a string, to solve this problem, i.e.

Code: Select all

base:FuncOnField(msg.id,"contents",LowerStr)