C# and Java Developer starting Lite-C programming.

Posted By: Crazykins

C# and Java Developer starting Lite-C programming. - 10/15/09 12:08

Lite-C is coming pretty fast for me. But it seems I am at a stand still. I did look at all of the tutorials, manual, and the AUM for this information. What I am trying to do is to have a mouse click on a model 1. Trigger the mouse clicked event. 2. Find out which house was clicked. 3. Load the appropriate level. Here is my code thus far:
Code:
BMAP* cursor = "cursor.tga";
var frame_speed = 0;
STRING* mystring = "You clicked the mouse!";

function main()
{
    video_mode = 9;
    video_screen = 1;
    level_load ("level1.wmb");
    mouse_mode += 1;
    mouse_map = cursor;
    
    while (1)
   {
      mouse_pos.x = mouse_cursor.x;
      mouse_pos.y = mouse_cursor.y;
       
      wait (1);
   }
}

function house_event()
   {
     if (event_type == EVENT_TOUCH) // the house was touched?
     {
       my.ambient = 50; // make it look bright
       my.lightrange = 50; // and generate light on a radius of 50 quants!
       
       while (frame_speed <= 101)
       {
       	ent_animate(my, "Move", frame_speed, ANM_CYCLE);
         frame_speed += 8 * time_step;
         wait(1);
       }
       frame_speed = 0;
       
       if (event_type == EVENT_CLICK)
       {
       	TEXT* myText =
			{
			    pos_x = 300;
			    pos_y = 250;
			    string (myString);
			    flags = SHOW;
			}
       }
     }
     else // the house isn't touched anymore
     {
         if (event_type == EVENT_RELEASE) // the mouse was moved away from it?
         {
               my.ambient = 0; // then restore its initial ambient value (zero)
               my.lightrange = 0; // and stop it from generating light around it
         }
     }
   }
   
   action house_selection() // this action is attached to both houses
   {  
     // make the house models sensitive to mouse touching and releasing
     my.emask = ENABLE_TOUCH | ENABLE_RELEASE;
     my.emask |= ENABLE_CLICK;
     my.event = house_event; 
   }



The lighting and animation on the mouse over event works perfectly. I am trying to test the mouse click with a message. The message is always up even if there were no mouse hover or click events. Which to me is weird. Why would it even execute before the event. This could be because of my background in C# and Java that I am just not getting why this is happening. The events are setup correctly as you can plainly see from the code. I also tried different flags and tried using toggle keyword but still the message is always up.

I also need help finding the correct keyword in Lite-C to get an object (model) from a mouse position. I can find little of this in the manual. I have the express version of 3dgs.

Thanks for your help! laugh
Posted By: pegamode

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 12:21

I think you have to use txt_create() to create a TEXT object at runtime.

I think there's some remark in the manual.

Regards,
Pegamode.

Posted By: Ottawa

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 13:54

Hi!
Place the code for :TEXT* myText

outside the event
and comment out this line
// flags = SHOW;

Then you can set or reset this flags in another function wink
Posted By: pegamode

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 14:23

Originally Posted By: Ottawa
Hi!
Place the code for :TEXT* myText

outside the event
and comment out this line
// flags = SHOW;

Then you can set or reset this flags in another function wink




Yes, I forgot to mention this ... otherwise you would have to use txt_create.
Posted By: Crazykins

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 21:47

ok this time I put the myText object under the myString object. And I changed my nested if statement to:
Code:
if (event_type == EVENT_CLICK)
       {
       	myText.flags = SHOW;
       }



It is still nested in my house_event function. It is still not working. I must be doing something wrong I just can't figure out what it is. frown

I even tried this:

Code:
action house_selection() // this action is attached to both houses
   {  
     // make the house models sensitive to mouse touching and releasing
     my.emask = ENABLE_TOUCH | ENABLE_RELEASE | ENABLE_CLICK;
     my.event = house_event; 
   }


and re assigning the action in WED. Nothing works.

Thanks though for all of your help! laugh
Posted By: Ottawa

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 23:29

Hi!

Your close wink

myText.flags = SHOW;
should be
myText.flags |= SHOW;

Look up the flags in the manual.
Look up set() reset() toggle ()
To help you with this part
pick up my contribution : Flags at a glance
in the resource section.
Posted By: Crazykins

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 23:43

I did finally get it to work! I had to take it out of my if statement nest for it to work. The working code is:
Code:
function house_event()
   {
     if (event_type == EVENT_TOUCH) // the house was touched?
     {
       my.ambient = 50; // make it look bright
       my.lightrange = 50; // and generate light on a radius of 50 quants!
       
       while (frame_speed <= 101)
       {
       	ent_animate(my, "Move", frame_speed, ANM_CYCLE);
         frame_speed += 8 * time_step;
         wait(1);
       }
       frame_speed = 0;
     }
     if (event_type == EVENT_CLICK)
     {
       	myText.flags |= SHOW;
     }
     else // the house isn't touched anymore
     {
         if (event_type == EVENT_RELEASE) // the mouse was moved away from it?
         {
               my.ambient = 0; // then restore its initial ambient value (zero)
               my.lightrange = 0; // and stop it from generating light around it
         }
     }
   }



For my function. Now that I have tested it comes the fun part of finding out which model the user clicks on. laugh
Posted By: Crazykins

Re: C# and Java Developer starting Lite-C programming. - 10/15/09 23:46

SWEET! Thanks guys for all of your help! Using this code works super well.

Code:
if (event_type == EVENT_CLICK)
     {
       	toggle(myText, SHOW);
     }



Thanks once again!
Posted By: Crazykins

Re: C# and Java Developer starting Lite-C programming. - 10/16/09 00:30

Thanks so much guys. Because of your help I was able to implement two actions and two entity objects to get which model was being selected by the user. Here is my code in case it may be able to help someone in the future. Thanks again! grin

Code:
ENTITY* houseOne;
ENTITY* houseTwo;
BMAP* cursor = "cursor.tga";
var frame_speed = 0;
STRING* myString_One = "You clicked on house one!";
STRING* myString_Two = "You click on house two!";
TEXT* myText_One =
			{
			    pos_x = 300;
			    pos_y = 250;
			    string (myString_One);
			}
TEXT* myText_Two =
			{
			    pos_x = 300;
			    pos_y = 250;
			    string (myString_Two);
			}

function main()
{
    video_mode = 9;
    video_screen = 1;
    level_load ("level1.wmb");
    mouse_mode += 1;
    mouse_map = cursor;
    
    while (1)
   {
      mouse_pos.x = mouse_cursor.x;
      mouse_pos.y = mouse_cursor.y;
       
      wait (1);
   }
}

function house_event()
   {
     if (event_type == EVENT_TOUCH) // the house was touched?
     {
       my.ambient = 50; // make it look bright
       my.lightrange = 50; // and generate light on a radius of 50 quants!
       
       while (frame_speed <= 101)
       {
       	ent_animate(my, "Move", frame_speed, ANM_CYCLE);
         frame_speed += 8 * time_step;
         wait(1);
       }
       frame_speed = 0;
     }
     if (event_type == EVENT_CLICK)
     {
       	if (houseOne == me)
       	{
       		toggle(myText_One, SHOW);
         }
         else
         {
         	if (houseTwo == me)
         	{
         		toggle(myText_Two, SHOW);
            }
         }
     }
     else // the house isn't touched anymore
     {
         if (event_type == EVENT_RELEASE) // the mouse was moved away from it?
         {
               my.ambient = 0; // then restore its initial ambient value (zero)
               my.lightrange = 0; // and stop it from generating light around it
         }
     }
   }
   
   action house_one_selection() // this action is attached to both houses
   {  
     // make the house models sensitive to mouse touching and releasing
     houseOne = me;
     my.emask = ENABLE_TOUCH | ENABLE_RELEASE | ENABLE_CLICK;
     my.event = house_event; 
   }
   
   action house_two_selection() // this action is attached to both houses
   {  
     // make the house models sensitive to mouse touching and releasing
     houseTwo = me;
     my.emask = ENABLE_TOUCH | ENABLE_RELEASE | ENABLE_CLICK;
     my.event = house_event; 
   }


Posted By: Ottawa

Re: C# and Java Developer starting Lite-C programming. - 10/16/09 13:32

Hi!

Happy to help laugh

Ottawa


PS : Here's something to read for posting.
In the FAQ read : What UBBCode can I use in my posts? wink
Posted By: Crazykins

Re: C# and Java Developer starting Lite-C programming. - 10/18/09 08:38

Thanks for the tip Ottawa! That looks much better now! grin
© 2023 lite-C Forums