Goofy question #7234

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Goofy question #7234

Richmond Mathewson via use-livecode
I am obviously missing something . . .

. . . so badly so that I've been trawling Danny Goodman's "Complete" HC
2 . . .

and NOT getting 'it' . . .

SO: one can set up a custom command:

on GoRed
   set the backGroundColor of card 1 to red
end GoRed

and one can call it:

on mouseUp
    do GoRed
end mouseUp

and one can set up a custom function:

function GoRed
   set the backGroundColor of card 1 to red
end function

Now: is the reason I cannot call that function because it takes NO
parameters?

Richmond.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Goofy question #7234

Richmond Mathewson via use-livecode
Hi Richmond

This works (both scripts in the button):
on mouseUp
put goRed()
end mouseUp

function goRed
set the backGroundColor of card 1 to red
end goRed

I think the general idea is that a function returns information. So
date() returns the date. But just having a line "date()" in the script
causes an error because you haven't told it what to do with the info
being returned. So you need "put data()" and then the info will go to
the message box.

Your function doesn't return any data. That's your choice when you write
it. But the engine is still expecting a function to return info, so you
still have to say "put" trigger the function.

You could write your function with a parameter:
function goRed foo
set the backGroundColor of foo to red
end goRed

Then call the function like this:
put goRed("card 1")
put goRed("card 3")
etc., and the one function can be used to turn both card 1 and card 3
(and any other object you specify in foo) red.

Hope that helps.

Tim Selander
Tokyo, Japan





On 7/10/17, 15:48, Richmond Mathewson via use-livecode wrote:

> I am obviously missing something . . .
>
> . . . so badly so that I've been trawling Danny Goodman's "Complete"
> HC 2 . . .
>
> and NOT getting 'it' . . .
>
> SO: one can set up a custom command:
>
> on GoRed
>   set the backGroundColor of card 1 to red
> end GoRed
>
> and one can call it:
>
> on mouseUp
>    do GoRed
> end mouseUp
>
> and one can set up a custom function:
>
> function GoRed
>   set the backGroundColor of card 1 to red
> end function
>
> Now: is the reason I cannot call that function because it takes NO
> parameters?
>
> Richmond.
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Goofy question #7234

Richmond Mathewson via use-livecode
It does help a lot: even if only to stop me looking totally 'Stoooopid'
in front
of the kids in my Summer classes.

Thanks.

Richmond.

On 7/10/17 11:09 am, Tim Selander via use-livecode wrote:

> Hi Richmond
>
> This works (both scripts in the button):
> on mouseUp
> put goRed()
> end mouseUp
>
> function goRed
> set the backGroundColor of card 1 to red
> end goRed
>
> I think the general idea is that a function returns information. So
> date() returns the date. But just having a line "date()" in the script
> causes an error because you haven't told it what to do with the info
> being returned. So you need "put data()" and then the info will go to
> the message box.
>
> Your function doesn't return any data. That's your choice when you
> write it. But the engine is still expecting a function to return info,
> so you still have to say "put" trigger the function.
>
> You could write your function with a parameter:
> function goRed foo
> set the backGroundColor of foo to red
> end goRed
>
> Then call the function like this:
> put goRed("card 1")
> put goRed("card 3")
> etc., and the one function can be used to turn both card 1 and card 3
> (and any other object you specify in foo) red.
>
> Hope that helps.
>
> Tim Selander
> Tokyo, Japan
>
>
>
>
>
> On 7/10/17, 15:48, Richmond Mathewson via use-livecode wrote:
>> I am obviously missing something . . .
>>
>> . . . so badly so that I've been trawling Danny Goodman's "Complete"
>> HC 2 . . .
>>
>> and NOT getting 'it' . . .
>>
>> SO: one can set up a custom command:
>>
>> on GoRed
>>   set the backGroundColor of card 1 to red
>> end GoRed
>>
>> and one can call it:
>>
>> on mouseUp
>>    do GoRed
>> end mouseUp
>>
>> and one can set up a custom function:
>>
>> function GoRed
>>   set the backGroundColor of card 1 to red
>> end function
>>
>> Now: is the reason I cannot call that function because it takes NO
>> parameters?
>>
>> Richmond.
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Goofy question #7234

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
Here is what I teach my students:

Use the function to return a value to the calling handler, set the properties in the handler, not in the function itself, like this:

on mouseUp
 set backgroundColor of this card to goRed()
end mouseUp

function goRed
  return “red”
end goRed

The benefit of this is that you can call the function from various handlers and sending whatever parameter you like. Here is a script that returns different colours
depending on which card you open when you call the function. Everything is placed in the stack script:

on preOpenCard
 put short name of this card into tCard
 set backgroundColor of card tCard to setColour(tCard)
end preOpenCard

function setColour pCard
 if pCard = “One” then
   return “red”
 else
   return “blue”
 end if
end setColour


Regards
Tore Nilsen

> 10. jul. 2017 kl. 10:09 skrev Tim Selander via use-livecode <[hidden email]>:
>
> Hi Richmond
>
> This works (both scripts in the button):
> on mouseUp
> put goRed()
> end mouseUp
>
> function goRed
> set the backGroundColor of card 1 to red
> end goRed
>
> I think the general idea is that a function returns information. So date() returns the date. But just having a line "date()" in the script causes an error because you haven't told it what to do with the info being returned. So you need "put data()" and then the info will go to the message box.
>
> Your function doesn't return any data. That's your choice when you write it. But the engine is still expecting a function to return info, so you still have to say "put" trigger the function.
>
> You could write your function with a parameter:
> function goRed foo
> set the backGroundColor of foo to red
> end goRed
>
> Then call the function like this:
> put goRed("card 1")
> put goRed("card 3")
> etc., and the one function can be used to turn both card 1 and card 3 (and any other object you specify in foo) red.
>
> Hope that helps.
>
> Tim Selander
> Tokyo, Japan
>
>
>
>
>
> On 7/10/17, 15:48, Richmond Mathewson via use-livecode wrote:
>> I am obviously missing something . . .
>>
>> . . . so badly so that I've been trawling Danny Goodman's "Complete" HC 2 . . .
>>
>> and NOT getting 'it' . . .
>>
>> SO: one can set up a custom command:
>>
>> on GoRed
>>  set the backGroundColor of card 1 to red
>> end GoRed
>>
>> and one can call it:
>>
>> on mouseUp
>>   do GoRed
>> end mouseUp
>>
>> and one can set up a custom function:
>>
>> function GoRed
>>  set the backGroundColor of card 1 to red
>> end function
>>
>> Now: is the reason I cannot call that function because it takes NO parameters?
>>
>> Richmond.
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Goofy question #7234

Richmond Mathewson via use-livecode
In the newfangled LC world, you can even do things the way the engine can -
using "return for value" (or just "return") and "return for error" to allow
commands to return values, too.  Then "it" gets values that are returned,
and "the result" gets errors that are returned.  9 is fun.
 funfunfunfunfunfunfun

On Mon, Jul 10, 2017 at 4:29 AM, Tore Nilsen via use-livecode <
[hidden email]> wrote:

> Here is what I teach my students:
>
> Use the function to return a value to the calling handler, set the
> properties in the handler, not in the function itself, like this:
>
> on mouseUp
>  set backgroundColor of this card to goRed()
> end mouseUp
>
> function goRed
>   return “red”
> end goRed
>
> The benefit of this is that you can call the function from various
> handlers and sending whatever parameter you like. Here is a script that
> returns different colours
> depending on which card you open when you call the function. Everything is
> placed in the stack script:
>
> on preOpenCard
>  put short name of this card into tCard
>  set backgroundColor of card tCard to setColour(tCard)
> end preOpenCard
>
> function setColour pCard
>  if pCard = “One” then
>    return “red”
>  else
>    return “blue”
>  end if
> end setColour
>
>
> Regards
> Tore Nilsen
>
> > 10. jul. 2017 kl. 10:09 skrev Tim Selander via use-livecode <
> [hidden email]>:
> >
> > Hi Richmond
> >
> > This works (both scripts in the button):
> > on mouseUp
> > put goRed()
> > end mouseUp
> >
> > function goRed
> > set the backGroundColor of card 1 to red
> > end goRed
> >
> > I think the general idea is that a function returns information. So
> date() returns the date. But just having a line "date()" in the script
> causes an error because you haven't told it what to do with the info being
> returned. So you need "put data()" and then the info will go to the message
> box.
> >
> > Your function doesn't return any data. That's your choice when you write
> it. But the engine is still expecting a function to return info, so you
> still have to say "put" trigger the function.
> >
> > You could write your function with a parameter:
> > function goRed foo
> > set the backGroundColor of foo to red
> > end goRed
> >
> > Then call the function like this:
> > put goRed("card 1")
> > put goRed("card 3")
> > etc., and the one function can be used to turn both card 1 and card 3
> (and any other object you specify in foo) red.
> >
> > Hope that helps.
> >
> > Tim Selander
> > Tokyo, Japan
> >
> >
> >
> >
> >
> > On 7/10/17, 15:48, Richmond Mathewson via use-livecode wrote:
> >> I am obviously missing something . . .
> >>
> >> . . . so badly so that I've been trawling Danny Goodman's "Complete" HC
> 2 . . .
> >>
> >> and NOT getting 'it' . . .
> >>
> >> SO: one can set up a custom command:
> >>
> >> on GoRed
> >>  set the backGroundColor of card 1 to red
> >> end GoRed
> >>
> >> and one can call it:
> >>
> >> on mouseUp
> >>   do GoRed
> >> end mouseUp
> >>
> >> and one can set up a custom function:
> >>
> >> function GoRed
> >>  set the backGroundColor of card 1 to red
> >> end function
> >>
> >> Now: is the reason I cannot call that function because it takes NO
> parameters?
> >>
> >> Richmond.
> >> _______________________________________________
> >> use-livecode mailing list
> >> [hidden email]
> >> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Goofy question #7234

Richmond Mathewson via use-livecode
That is cool. As soon as 9 release candidates are released I will have to look hard at v9. Unfortunately I do not develop for a living (exactly) so I do not have a lot of time for running a DP through it's paces.

Bob S


> On Jul 10, 2017, at 06:01 , Mike Kerner via use-livecode <[hidden email]> wrote:
>
> In the newfangled LC world, you can even do things the way the engine can -
> using "return for value" (or just "return") and "return for error" to allow
> commands to return values, too.  Then "it" gets values that are returned,
> and "the result" gets errors that are returned.  9 is fun.
> funfunfunfunfunfunfun


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Goofy question #7234

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
I wrote this explanation a long time ago for someone else:
http://www.hyperactivesw.com/resources_function.html

Also, in your command handler example, you don't need "do" which adds
unnecessary overhead. This is enough:

on mouseUp
  GoRed
end mouseUp

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com



On July 10, 2017 1:50:39 AM Richmond Mathewson via use-livecode
<[hidden email]> wrote:

> I am obviously missing something . . .
>
> . . . so badly so that I've been trawling Danny Goodman's "Complete" HC
> 2 . . .
>
> and NOT getting 'it' . . .
>
> SO: one can set up a custom command:
>
> on GoRed
>    set the backGroundColor of card 1 to red
> end GoRed
>
> and one can call it:
>
> on mouseUp
>     do GoRed
> end mouseUp
>
> and one can set up a custom function:
>
> function GoRed
>    set the backGroundColor of card 1 to red
> end function
>
> Now: is the reason I cannot call that function because it takes NO
> parameters?
>
> Richmond.
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...