3 registered members (TipmyPip, AndrewAMD, dBc),
18,430
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
click button not working
#304823
01/11/10 01:26
01/11/10 01:26
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
I don't get it. Why doesn't this work? I've tried everthing I could think of and I can get the left mouse click on the button to work. Here is my code:
function mouse_event()
{
if (event_type == EVENT_TOUCH)
{ // if the model was touched with the mouse
set(my,BRIGHT|UNLIT);
my.ambient = 20; // make it look bright
my.lightrange = 80; // generate light on a radius of 'x' quants!
}
else if (event_type == EVENT_TOUCH && event_type == EVENT_CLICK)
{ // if the model was clicked with the mouse
my.ambient = 0; // make it look bright
my.lightrange = 0; // generate light on a radius of 'x' quants!
while (my.frame < 20)
{
my.frame += 1 * time_step;
if (my.frame >= 20) {my.frame = 20;}
wait(1);
}
}
else if (event_type == EVENT_RELEASE)
{ // if the mouse was moved away from it
my.ambient = -50; // then restore its initial ambient value (zero)
my.lightrange = 0; // and stop it from generating light around it
while (my.frame > 0)
{
my.frame -= 1 * time_step;
if (my.frame <= 0) {my.frame = 0;}
wait(1);
}
}
}
action nameAction()
{
my.ambient = -75;
my.pan = 50;
//my.roll = 75;
my.y = 35;
// make the model sensitive to mouse touching and releasing
my.emask |= (ENABLE_TOUCH | ENABLE_RELEASE | EVENT_CLICK);
// run function mouse_event when the model is touched or released
my.event = mouse_event;
}
The button is supposed to animate when I left click with the mouse, but it doesn't. If I place the code... while (my.frame < 20) { my.frame += 1 * time_step; if (my.frame >= 20) {my.frame = 20;} wait(1); }...under EVENT_TOUCH, the button animates. Why doesn't it animate under EVENT_CLICK? I even tried using: if (mouse_left) which doesn't work either. Can someone help me with this please?
|
|
|
Re: click button not working
[Re: JGGamer]
#304923
01/11/10 21:37
01/11/10 21:37
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
Serious User
Joined: Sep 2009
Posts: 1,032
Budapest
|
In your code:
if (event_type == EVENT_TOUCH)
{
... here we are if EVENT_TOUCH happened
}
else
Every thing AFTER the else is related to those events that AREN'T EVENT_TOUCH. So... The second if right next the else contains such condition that will never occur because implies the event_type == EVENT_TOUCH and that is exluded in this branch. The skeleton of the if-then-else statememnt.
if (condittion)
{
codelines for the condition TRUE branch
}
else
{
codelines for the condition FALSE branch
}
Hope this help. edit reason: bold doesnt work for me inside code tags.
Last edited by Aku_Aku; 01/11/10 21:39.
|
|
|
Re: click button not working
[Re: JGGamer]
#305047
01/12/10 17:42
01/12/10 17:42
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
Serious User
Joined: Sep 2009
Posts: 1,032
Budapest
|
Did you tried to use this:
else if (event_type == EVENT_CLICK)
instead if this:
else if (event_type == EVENT_TOUCH && event_type == EVENT_CLICK)
? If not, do it...
|
|
|
Re: click button not working
[Re: Aku_Aku]
#305272
01/13/10 21:39
01/13/10 21:39
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
|
|
|
Re: click button not working
[Re: Aku_Aku]
#305479
01/15/10 00:18
01/15/10 00:18
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi!
Have you thought of using case Separating the over and touched
if over on case (1) and so on.
if clicked on case (1) and so on.
Hope this helps! Ottawa  Ver 7.86.2 Pro and Lite-C
|
|
|
Re: click button not working
[Re: JGGamer]
#305676
01/16/10 13:47
01/16/10 13:47
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
Serious User
Joined: Sep 2009
Posts: 1,032
Budapest
|
function mouse_event()
{
if (event_type == EVENT_TOUCH)
{ // if the model was touched with the mouse
set(my,BRIGHT|UNLIT);
my.ambient = 20; // make it look bright
my.lightrange = 80; // generate light on a radius of 'x' quants!
}
else if (event_type == EVENT_CLICK)
{ // if the model was clicked with the mouse
my.ambient = 0; // make it look bright
my.lightrange = 0; // generate light on a radius of 'x' quants!
while (my.frame < 20)
{
my.frame += 1 * time_step;
if (my.frame >= 20) {my.frame = 20;}
wait(1);
}
}
else if (event_type == EVENT_RELEASE)
{ // if the mouse was moved away from it
my.ambient = -50; // then restore its initial ambient value (zero)
my.lightrange = 0; // and stop it from generating light around it
while (my.frame > 0)
{
my.frame -= 1 * time_step;
if (my.frame <= 0) {my.frame = 0;}
wait(1);
}
}
}
I am curious, why doesn't work this code? Perhaps i can help you, if you write here what happens... Or both of we can learn something.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|