Page 1 of 1

Functions - Trying to wrap brain around this

Posted: Thu Mar 20, 2014 9:47 pm
by gpearson
In my application development, I use functions with actionscript but having issues with a function in Livecode. To save me time in creating a custom popup box in my application, I am wanting to do with with a function so I can pass string parameters to the function but at this time it is not working.

In my application if the application is not supported on the device, I am wanting to do the following

Code: Select all

put "Missing Platform Case Statement" into tMsgHeader
      put "Platform is " & the platform & cr into tMsgBody
      put "System Version is " & the systemversion & cr  after tMsgBody
      put " " & cr after tMsgBody
      put "$HOMEDRIVE is " & $HOMEDRIVE & cr after tMsgBody
      put "$COMPUTERNAME is " & $COMPUTERNAME & cr after tMsgBody
      put "$HOME is " & $HOME & cr after tMsgBody
      put "$OS is " & $OS & cr after tMsgBody
      put " " & cr after tMsgBody
      put "This version of this application does not run on your device at this time. If you contact us with the above information, we will add this device to our list of supported devices. " after tMsgBody
      put " We will then contact you to see if you would be willing to test the software on this device.  We would like for you to send us a message " after tMsgBody
      put " with the information in this window so that we can update our software for your platform. " & cr after tMsgBody
      put true into tBtn1Visible
      put 1 into tNumButtons
      put "Quit_Button" into tBtn1Name
      AlertMessageDialog(tMsgHeader, tMsgBody, tNumButtons, tBtn1Name, tBtn1Visible)
Now my function is currently set to

Code: Select all

on AlertMessageDialog HeaderText,MessageText,NumberButtons,Button1Name,Button1Visible
   put "" into fld "Header Field" on card "Alerts" of stack "TruckersWallet"
   put "" into fld "Alert Message" on card "Alerts" of stack "TruckersWallet"
   put HeaderText into fld "Header Field" on card "Alerts" of stack "TruckersWallet"
   -- put MessageText into fld "Alert Message" on card "Alerts" of stack "TruckersWallet"
   
   // if NumberButtons = 1 then
      // set the visible of btn Button1Name on card "Alerts" of stack "TruckersWallet" to Button1Visible
   // end if
   go card "Alerts" of stack "TruckersWallet"
end AlertMessageDialog
If I put a break and run the application, all of the information passed into this is within the first variable if HeaderText. Here is what that variable holds

Missing Platform Case Statement,Platform is Win32
System Version is NT 6.1

$HOMEDRIVE is C:
$COMPUTERNAME is GPEARSON-LAPPC
$HOME is
$OS is Windows_NT

This version of this application does not run on your device at this time. If you contact us with the above information, we will add this device to our list of supported devices. We will then contact you to see if you would be willing to test the software on this device. We would like for you to send us a message with the information in this window so that we can update our software for your platform.
,1,Quit_Button,true


Is this the desired operation? Anyway to get each of the information between the ,'s to be in their own variable without using the split command.

Re: Functions - Trying to wrap brain around this

Posted: Thu Mar 20, 2014 9:55 pm
by Klaus
Hi Graham,

that is not a function but a handler, but you call it like a function! 8)
ON AlertMessageDialog <> function AlertMessageDialog

So just leave out the parens and everything will be fine:
...
AlertMessageDialog tMsgHeader, tMsgBody, tNumButtons, tBtn1Name, tBtn1Visible
...

Best

Klaus

Re: Functions - Trying to wrap brain around this

Posted: Thu Mar 20, 2014 10:12 pm
by dave.kilroy
Hi Graham

Although you are referring to AlertMessageDialog as a function, it is in fact a command (your AlertMessageDialog is declared with the word "on").

Commands and functions are different to each other (functions return a value, commands [usually] don't). You call functions with parameters inside brackets - but with commands if you were to put stuff meant to be parameters inside brackets they would be treated as a single parameter - which is what seems to be you are experiencing.

Try removing the brackets in your call AlertMessageDialog - as in:

Code: Select all

AlertMessageDialog tMsgHeader, tMsgBody, tNumButtons, tBtn1Name, tBtn1Visible
BTW you can also declare a command with the "command" word, as far as I'm aware "command" is a synonym of "on" but there may be some subtle difference between the two...

Good luck!

Re: Functions - Trying to wrap brain around this

Posted: Thu Mar 20, 2014 10:20 pm
by dave.kilroy
Hi Klaus - you got your response in before me! And it's shorter and clearer! :)

Re: Functions - Trying to wrap brain around this

Posted: Fri Mar 21, 2014 5:36 pm
by Klaus
Well, I'm not a friend of many words :D

Re: Functions - Trying to wrap brain around this

Posted: Fri Mar 21, 2014 6:52 pm
by dave.kilroy
Klaus well with 5630 posts against your name (that is the figure as I'm writing this, but the number keeps on rising) I think that you are pretty good with words, with LiveCode and with self-deprecating and modest remarks :)