Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (Grant, TipmyPip, AndrewAMD), 12,724 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Senior Member
Eagelina  Offline 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 clicked

Code:
function 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;

}


Code:
////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. smile
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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
Code:
#define __class skill1
	#define _class_candle 1

have the function that'll determine what the light does
Code:
//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
Code:
//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
Code:
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: MrGuest] #271870
06/15/09 14:06
06/15/09 14:06
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
i made you a quick working demo also if you want it , get it here
get here

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 Offline OP
Senior Member
Eagelina  Offline 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.... grin The goal with this is that the player must "light" several candles in a spesial order....to get the key..... wink


A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
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 Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
@MrGuest
I had to ad this code to make it work:

Code:
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..... grin for me anyway..... Thanks!


A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
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 Offline OP
Senior Member
Eagelina  Offline 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. smile
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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
Code:
function click_light(ENTITY* ent_temp){



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1