String interpolation

Discuss any general programming issues here
Post Reply
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

String interpolation

Post by djrikki » Sun Mar 18, 2018 12:05 pm

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
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com

djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: String interpolation

Post by djrikki » Sun Mar 18, 2018 12:42 pm

(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!
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com

User avatar
airsoftsoftwair
Posts: 2506
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: String interpolation

Post by airsoftsoftwair » Tue Mar 20, 2018 8:34 pm

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)

Post Reply