|
3 registered members (bigsmack, 3run, AndrewAMD),
37,438
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
How can I do this better? ENABLE_TOUCH
#271852
06/15/09 12:18
06/15/09 12:18
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
This is what I am trying to do: A model of a candle is in the game. Unligt is ticked in the properties. So the model is dark. I have added some text, that shows when the candle are touched, and that works fine.... But this dont..... What I whant is the player touch with mousepointer and left click with mouse and then the candle will be lighted up setting the ambient to 100. Problem is that it takes forever to react. I click on the candle and I have to click many times and some times it works and some time it dont. Does any of you have any suggestion on how to make it react faster? I whant the candle to get ambient to 100 as soon as the mouse is clickedfunction display_light()
{
set (message_txt, VISIBLE);
wait (-1);
reset (message_txt, VISIBLE);
if(mouse_left)
{
if(mouse_ent)
{
my.ambient = 100;
}
}
}
action lyse_stake()
{
set(my,PASSABLE);
my.emask |= (ENABLE_TOUCH);
my.event = display_light;
}////mouse/////
function mouse_startup()
{
mouse_mode = 2;
//mouse_range=5000;
mouse_map = bmp_mouse_ptr;
while (1)
{
vec_set(mouse_pos, mouse_cursor);
wait(1);
}
}
/////////////
Last edited by Eagelina; 06/15/09 12:39.
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How can I do this better? ENABLE_TOUCH
[Re: Eagelina]
#271863
06/15/09 13:47
06/15/09 13:47
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
heya, whenever i use entities in a game, i define them with a class (__class) so i know know what they are when using them #define __class skill1
#define _class_candle 1
have the function that'll determine what the light does //operate candle
function click_light(ENTITY* _ent){
//toggle the ambience
_ent.ambient = 100 - _ent.ambient; //100 - 100 = 0 || 100 - 0 = 100
//display text
set(message_txt, SHOW);
//wait 1 second
wait(-1);
//hide text
reset(message_txt, SHOW);
}have 1 function that catches all mouse_clicks, i've shortened here though so you can see what's happening easier //catches all mouse_left clicks
function mouse_click(){
//if hit any entity
if(mouse_ent){
//see what's being clicked
switch(mouse_ent.__class)
//if candle
case _class_candle:
//call click_light
click_light(mouse_ent);
break;
}
}
}
then set your mouse function for left clicks void main(){
mouse_mode = 4;
on_mouse_left = mouse_click;
}also if you use mouse_mode = 4; it'll save using while(1) vec_set(mouse_pos, mouse_cursor etc... Hope this helps! *untested*
|
|
|
Re: How can I do this better? ENABLE_TOUCH
[Re: Eagelina]
#271873
06/15/09 14:20
06/15/09 14:20
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
@MrGuest Thanks for the suggestion , I will try it out later today. @badapple Thanks I have downloaded it and: Wow you made much more than I whanted. I will use the evening to study the code. ------------------------------- Thanks! Now are there going to be a lot of candles in my game....  The goal with this is that the player must "light" several candles in a spesial order....to get the key..... 
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How can I do this better? ENABLE_TOUCH
[Re: MrGuest]
#272097
06/16/09 13:15
06/16/09 13:15
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
@MrGuest I had to ad this code to make it work: action light()
{
my.emask |= ENABLE_CLICK;
my.event = click_light;
my.ambient=-100;
} By the way isent this way of coding (your code) like Object Oriented Programming? It looks a lot like we did program with Java, and I have been coding with different of C(+, ++, # )that I have seen the same. And yes it is much better to program this way, it is so much easy to "understand" it.....  for me anyway..... Thanks!
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How can I do this better? ENABLE_TOUCH
[Re: MrGuest]
#272107
06/16/09 13:58
06/16/09 13:58
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
If I am not wrong mrguest, so is some of the code C-script.... I am only using Lite-C.
Eksample: when I select this in SED it says C-script
function click_light(ENTITY* _ent) <--- The ENTITY* _ent does sed say that it is C-script.
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How can I do this better? ENABLE_TOUCH
[Re: Eagelina]
#272196
06/16/09 21:28
06/16/09 21:28
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
all of the code there is lite-c, some of it's probably CScript too, but it's been quite a while since i've used it, i wouldn't be able to tell you which part try just renaming _ent to something similar function click_light(ENTITY* ent_temp){
|
|
|
|