click button not working

Posted By: JGGamer

click button not working - 01/11/10 01:26

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:

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?
Posted By: Aku_Aku

Re: click button not working - 01/11/10 21:37

In your code:
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.
Code:
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.
Posted By: JGGamer

Re: click button not working - 01/12/10 02:55

Well, you have pointed out a fact, but it hasn't helped me with my problem. Like I said, I tried everything I could think of, including not using 'else', and still it doesn't work.
Posted By: Aku_Aku

Re: click button not working - 01/12/10 17:42

Did you tried to use this:
Code:
else if (event_type == EVENT_CLICK)


instead if this:
Code:
else if (event_type == EVENT_TOUCH && event_type == EVENT_CLICK)


?

If not, do it...
Posted By: JGGamer

Re: click button not working - 01/13/10 21:39

I did.
Posted By: Aku_Aku

Re: click button not working - 01/14/10 22:25

Good
Posted By: Ottawa

Re: click button not working - 01/15/10 00:18

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.
Posted By: JGGamer

Re: click button not working - 01/16/10 01:52

Aku Aku
No, it's nt good, because it didn't work.

Ottawa
I'll try that, thanks.
Posted By: Aku_Aku

Re: click button not working - 01/16/10 13:47

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_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.
Posted By: JGGamer

Re: click button not working - 01/17/10 01:30

Your curious...??? I'm perplexed, puzzled..., you name it.
I can't write what happens, other than that the button doesn't animate when I click on it with the mouse. Like I said before, if I place the animation under EVENT_TOUCH, the button animates as soon as I move the mouse over it. That's strange to me. Thanks for your effort.
Posted By: Aku_Aku

Re: click button not working - 01/17/10 09:48

To be sure what does the processing of the click, put a message or something else that gives you a sign "Hey here we are!", immediatly after the "IF".
Normally, all the "IF" branches should work in this code. So i suspect there is another thing what leads you to think a branch doesn't work.
Posted By: Ottawa

Re: click button not working - 01/17/10 15:26

Hi JGGamer!

You now have the events all in a group and value is true for some and never for the other.
Try separating the events
Get rid of the else in the function
If it's over do this...
If it's clicked do this
Posted By: JGGamer

Re: click button not working - 01/18/10 05:02

I tried everything I could think of, as I said before. Using case gives the same result - no change.
Thanks for trying fellows, but I think we had better close this thread. I think I'll try a workaround instead of using this feature. Thanks
Posted By: GorNaKosh

Re: click button not working - 01/18/10 07:07

This is strange ... There have to be a solution for this ^^ Give us the whole source of the panel definition an so on, pls. Then we could test your code and debugg with our own methods to tell you where is the catch. Do you have set all three function-pointers functionOn, functionOff, functionOver in the button definition?
Posted By: JGGamer

Re: click button not working - 01/18/10 15:30

I don't believe the problem lies with the code, because the animation works with the mouse over, but not with the mouse click, so I believe it has to do with the animation. I prefer not to go through this however, because I observed that it does not work to my liking. If I move the mouse over the button and the animation starts, if I quickly move the mouse off the button, the animation if left in mid-action, and does not complete as it should. This I don't want, so I will find an alternative to this. Please don't bother with it. Thanks for the interest in helping.
Posted By: Aku_Aku

Re: click button not working - 01/18/10 21:27

My experiences show that, in such cases 100% the mistake is in the code. The remaining 0,1% in the engine. cool
But if you wish, i don't try more.
© 2024 lite-C Forums