Functions - Trying to wrap brain around this

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Functions - Trying to wrap brain around this

Post by gpearson » Thu Mar 20, 2014 9:47 pm

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.
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Functions - Trying to wrap brain around this

Post by Klaus » Thu Mar 20, 2014 9:55 pm

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

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Functions - Trying to wrap brain around this

Post by dave.kilroy » Thu Mar 20, 2014 10:12 pm

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!
"...this is not the code you are looking for..."

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Functions - Trying to wrap brain around this

Post by dave.kilroy » Thu Mar 20, 2014 10:20 pm

Hi Klaus - you got your response in before me! And it's shorter and clearer! :)
"...this is not the code you are looking for..."

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Functions - Trying to wrap brain around this

Post by Klaus » Fri Mar 21, 2014 5:36 pm

Well, I'm not a friend of many words :D

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Functions - Trying to wrap brain around this

Post by dave.kilroy » Fri Mar 21, 2014 6:52 pm

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 :)
"...this is not the code you are looking for..."

Post Reply