2 registered members (TipmyPip, 1 invisible),
18,789
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Reselect Unit
#202706
04/16/08 16:07
04/16/08 16:07
|
Joined: May 2007
Posts: 185 Netherlands
SurudoiRyu
OP
Member
|
OP
Member
Joined: May 2007
Posts: 185
Netherlands
|
Hi there i was wondering if anyone could help with my piece of code. this script can select units now and deselect them with right mouse button but when i got one unit selected it wont select another unit and deselect the current selected unit  Can someone help me fix it so that when i click another unit it deselects the current unit and selects the other unit ? Thnx in advance Here is my code
//////////////////////////////
// Ingame Unit Control
//////////////////////////////
//var Unit_Selected[30]; //cant store entity in array...
var own_unit;
var secondtry;
string bmp_selected, <Selected.bmp>;
function highlight_me()
{
if (event_type == event_click)
{
play_random_snd_hfx();
if(own_unit==0)
{Selection();secondtry=1;}
}
if (event_type == event_touch)
{
my.ambient = 100;
}
while (event_type != event_release) {wait (1);}
my.ambient = 0;
}
function DoubleCheck()
{
while(1)
{
if(own_unit==1&&secondtry==1)
{
ent_remove(me);
}
wait(1);
}
}
function Selection()
{
if (!own_unit == 1)
{
me = ent_create (bmp_selected,vector (my.x,my.y,my.z-15 ),DoubleCheck());
me.tilt = 90;
own_unit = 1;
while(!mouse_right)
{
me.pan +=-0.2;
wait(1);
if(mouse_right)
{
own_unit = 0;
secondtry = 0;
ent_remove(me);
}
}
}
}
action my_unit
{
my.enable_touch = on;
my.enable_click = on;
my.enable_release = on;
my.event = highlight_me;
}
//////////////////////////////
// End
//////////////////////////////
-The Dragon's Eye is alway's watching you!-
|
|
|
Re: Reselect Unit
[Re: SurudoiRyu]
#202736
04/16/08 17:50
04/16/08 17:50
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
while (event_type != event_release) {wait (1);}
my.ambient = 0; This is very dangerous code. It is not guaranteed to be executed at all. As a general rule you should never place any waits in event functions. Better write
if (event_type == event_release) {
my.ambient = 0;
} Additionally you should change "(!own_unit == 1)" to "(own_unit != 1)" or "(!(own_unit == 1))". Does this solve your problem?
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Reselect Unit
[Re: Uhrwerk]
#202765
04/16/08 21:06
04/16/08 21:06
|
Joined: May 2007
Posts: 185 Netherlands
SurudoiRyu
OP
Member
|
OP
Member
Joined: May 2007
Posts: 185
Netherlands
|
Thnx for the tip! ^-^ But the other code isn't working It still keeps the other one selected  Maybe cause i didn't store the entity and he doesn't know which one to remove ? How can i put entity's in an array? Could you help me put it in my script ? this is the updated script
//////////////////////////////
// Ingame Unit Control
//////////////////////////////
var Unit_Selected[30];
var own_unit;
var secondtry;
string bmp_selected, <Selected.bmp>;
function highlight_me()
{
if (event_type == event_click)
{
play_random_snd_hfx();
if(own_unit==0)
{Selection();secondtry=1;}
}
if (event_type == event_touch)
{
my.ambient = 100;
}
if (event_type == event_release) {my.ambient = 0;}
}
function DoubleCheck()
{
while(1)
{
if(own_unit==1&&secondtry==1)
{
ent_remove(me);
}
wait(1);
}
}
function Selection()
{
if (!(own_unit == 1))
{
me = ent_create (bmp_selected,vector (my.x,my.y,my.z-15 ),NULL);
me.tilt = 90;
own_unit = 1;
while(!mouse_right)
{
me.pan +=-0.2;
wait(1);
if(mouse_right)
{
own_unit = 0;
secondtry = 0;
ent_remove(me);
}
}
}
else
{
DoubleCheck();
}
}
action my_unit
{
my.enable_touch = on;
my.enable_click = on;
my.enable_release = on;
my.event = highlight_me;
}
//////////////////////////////
// End
//////////////////////////////
-The Dragon's Eye is alway's watching you!-
|
|
|
Re: Reselect Unit
[Re: SurudoiRyu]
#202782
04/16/08 23:08
04/16/08 23:08
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Sorry, I won't debug your code. But I'll give you an example based on your code how such a simple selection algorithm could work: //////////////////////////////
// Ingame Unit Control
//////////////////////////////
string bmp_selected = "Selected.bmp";
entity* selectedUnit;
action Selection()
{
me.tilt = 90;
while ((!mouse_right) && (selectedUnit == you))
{
me.pan += time_step;
wait(1);
}
ent_remove(me);
}
function highlight_me()
{
if ((event_type == event_click) && (selectedUnit != me))
{
play_random_snd_hfx();
selectedUnit = me;
ent_create(bmp_selected,vector(my.x,my.y,my.z - 15),Selection);
}
if (event_type == event_touch)
{
my.ambient = 100;
}
if (event_type == event_release)
{
my.ambient = 0;
}
}
action my_unit
{
my.enable_touch = on;
my.enable_click = on;
my.enable_release = on;
my.event = highlight_me;
} Storing entities in an array is quite simple. Define an array and write "arrayname[x] = me;" for example.
Last edited by Uhrwerk; 04/16/08 23:25. Reason: Kleiner Patzer im Code.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Reselect Unit
[Re: Uhrwerk]
#202787
04/16/08 23:45
04/16/08 23:45
|
Joined: May 2007
Posts: 185 Netherlands
SurudoiRyu
OP
Member
|
OP
Member
Joined: May 2007
Posts: 185
Netherlands
|
Cool thnx for the help im busy trying to understand the code now but i figure out how you did it. Thnx for this it works even better 
-The Dragon's Eye is alway's watching you!-
|
|
|
Re: Reselect Unit
[Re: SurudoiRyu]
#202788
04/16/08 23:55
04/16/08 23:55
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
You're welcome. Be carefull when you write something into the me pointer. It's in most cases better, to create an entity with a certain action.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Reselect Unit
[Re: Uhrwerk]
#203065
04/19/08 10:28
04/19/08 10:28
|
Joined: May 2007
Posts: 185 Netherlands
SurudoiRyu
OP
Member
|
OP
Member
Joined: May 2007
Posts: 185
Netherlands
|
Hi, One more question. I tried to make now a sort of multiselect with you code. But it screw's up everything a bit >.< I tried to define skills and check if it is 1 or not. but or it doesnt help and gives errors or you can place 1000 select's on 1 unit. Im doing multi select when you click 1 unit but when you hold shift you can click more units and select them. but i think cause of the me and you thing. Me is the circle and you is the unit. (for the selection circle) is it possible to have more me's ? or more you's ?  (lol that sounds funny) Or how do i store them in an array ? cause entity* selectedUnit[30]; doesn't work :s Hope you can help me Take care,
-The Dragon's Eye is alway's watching you!-
|
|
|
Re: Reselect Unit
[Re: SurudoiRyu]
#203104
04/19/08 15:08
04/19/08 15:08
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
It's not possible to have multiple yous and mes except for if you suffer from some psychic diseases like schizophrenia.  No, honestly, you only have one me and one you pointer. Everything else would disturb the engine logic. Using an array like "ENTITY* selectedUnit[30]" is a possible solution. Maybe you forgot the capital letters? If you post your code we can see if we get it to work together.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Reselect Unit
[Re: Uhrwerk]
#203112
04/19/08 16:25
04/19/08 16:25
|
Joined: May 2007
Posts: 185 Netherlands
SurudoiRyu
OP
Member
|
OP
Member
Joined: May 2007
Posts: 185
Netherlands
|
Well at the moment i have this. I tryed to make it move with the selection circle. And it works now. Also the first version was bugged when i clicked right en then left again it didnt select the unit now it does. Owyeah and this doesn't work "ENTITY* selectedUnit[30];" it gives an error cause the [30] behind it  here is the code.
//////////////////////////////
// Ingame Unit Control
//////////////////////////////
var Building_Powerplant;
var Building_Powerplant_X = 0;
var Powerplant_time = 10;
var own_unit;
var secondtry;
var dontmove;
string bmp_selected = "Selected.bmp";
ENTITY* selectedUnit;
action Selection()
{
me.tilt = 90;
while ((!mouse_right) && (selectedUnit == you))
{
my.x = you.x;
my.y = you.y;
my.z = you.z-15;
me.pan += time_step;
wait(1);
}
selectedUnit = null;
ent_remove(me);
}
function highlight_me()
{
if ((event_type == event_click) && (selectedUnit != me))
{
play_random_snd_hfx();
selectedUnit = null;
wait(1);
selectedUnit = me;
wait(1);
ent_create(bmp_selected,vector(my.x,my.y,my.z - 15),Selection);
}
if (event_type == event_touch)
{
dontmove = 1;
my.ambient = 100;
}
if (event_type == event_release)
{
dontmove = 0;
my.ambient = 0;
}
}
action my_unit
{
my.enable_touch = on;
my.enable_click = on;
my.enable_release = on;
my.event = highlight_me;
}
function move_unit()
{
if ((selectedUnit) && (dontmove == 0))
{
selectedUnit.x += 15;
}
}
on_mouse_left = move_unit;
//////////////////////////////
// End
//////////////////////////////
Last edited by SurudoiRyu; 04/19/08 16:51.
-The Dragon's Eye is alway's watching you!-
|
|
|
Re: Reselect Unit
[Re: SurudoiRyu]
#203158
04/20/08 00:17
04/20/08 00:17
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Oh, my fault. This is the C-Script forum. I'm always thinking in Lite-C. You can't have entity arrays in C-Scritp. However, you can define an array like "var myArray[20];". Then you can store even entities in this array. C-Script won't bother if you store pointers, handles, variables or whatever in the arrays you define. I'll have a look at your code.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|