|
2 registered members (Quad, AndrewAMD),
1,007
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: function not effecting neighbour
[Re: rtsgamer706]
#322164
05/05/10 01:33
05/05/10 01:33
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
I think I see two problems here. In your invader_one action you write "ene = me". This won't work. Every time this function is startet ene is overwritten so that "ene" will finally point to the last invader you created, the one at 0,-8050,520.
Second thing jumping to my eye ist that you're trying to remove the rocket twice. Once in the action rocket and the other time in explode(). Removing entities twice will result in a crash.
In general I recommend not using global pointers, like rocket or ene. This often leads to confusion. There are well reasoned exceptions, like for your turret.
Are you aware your local variable "there" has no effect?
If none of the hints work, try the following: Create a new project. Add a single entity in WED and assign an action that does nothing more but moving the entity in a while loop. From there you can continue to increase the complexity of your project step by step. Be sure to test regularly. The earlier you notice an error, the easier it is to find.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: function not effecting neighbour
[Re: rtsgamer706]
#322568
05/07/10 22:12
05/07/10 22:12
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Every invader has to run it's own action, that's right. But they are all equal. So you can assign the same action to all of your invaders, but the me pointer will be different for each entity when the game starts.
So you got an invalid argument in explode. If you haven't changed the code the error can only come from either ent_morph(me, "pixlexplo.mdl") or ent_remove(missile) or ent_remove(me). Comment all three lines out with a double slash like
// ent_remove(me)
The error should be gone. Remove one comment marker after the other. If the error reoccurs you found out which line gives the crash and you can think about the reason for this.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: function not effecting neighbour
[Re: Uhrwerk]
#322582
05/07/10 23:13
05/07/10 23:13
|
Joined: Dec 2009
Posts: 361
rtsgamer706
OP
Senior Member
|
OP
Senior Member
Joined: Dec 2009
Posts: 361
|
Thanks smart idea, I found that the problem is
ent_remove(missile); but I now have some new problems! If I put
ent_remove(me);
in an action tied to the rocket by a my.event line of code the missile just won't disappear no matter what happens. The other problem (get ready this is a weird one) is that once I have gotten rid of the line
ent_remove missile
all except one of the invaders explode! I have no clue why please help. thanks rtsgamer706
here is my entire code (I know most of the ent_creates are commented I am testing with the first nine invaders):
////////////////////////////////////////////////////////////////////// ENTITY* tank; ////////////////////////////////////////////////////////////////////// ENTITY* missile; ////////////////////////////////////////////////////////////////////// ENTITY* ene; //////////////////////////////////////////////////////////////////////
var invader_left = 24;
var missile_on = 0;
action miss_boom() { if(event_type == EVENT_IMPACT) { wait(1); ent_remove(me); } }
action explode() { if(event_type == EVENT_IMPACT) { ent_morph(me, "pixlexplo.mdl"); wait(1); wait (-0.25); ent_remove(me); missile_on = 0; invader_left -= 1; } }
action invader_1() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_2() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_3() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_4() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_5() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_6() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_7() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_8() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_9() { my.pan = -90; my.emask |= (ENABLE_IMPACT); c_setminmax(me); my.event = explode; ////////////////////////////////// c_move (me, vector(-100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(-1); c_move (me, vector(100, 0, 0), nullvector, GLIDE); // move invaders wait(1); }
action invader_ai() { }
action rocket() { my.emask |= (ENABLE_IMPACT); missile = me; missile_on += 120; var there = 1; my.event = miss_boom; while (1) { c_move (my, vector(0*time_step, 0,11), nullvector, GLIDE); // move the rocket up if (there == 1) missile_on -= 1; if (missile_on <= 0) { missile_on = 0; there = 0; // ent_remove(me); } wait(1); } }
action si_tank() { tank = me; while (1) { if (key_cur) { c_move (my, vector(0*time_step, -5.5, 0), nullvector, GLIDE); // move the tank right } if (key_cul) { c_move (my, vector(0*time_step, 5.5, 0), nullvector, GLIDE); // move the tank left } if (key_space) { if (missile_on <= 1) ent_create("si_rocket.mdl", vector (me.x, me.y, me.z+70), rocket); //create your tank } wait (1); } }
function main() { video_screen = 1; video_mode = 7; level_load (""); ent_create("tank.mdl", vector (0, 50, -300), si_tank); //create your tank ent_create("invader_I.mdl", vector (0, 750, 300), invader_1); //create an enemy ent_create("invader_I.mdl", vector (0, 550, 300), invader_2); //create an enemy ent_create("invader_I.mdl", vector (0, 350, 300), invader_3); //create an enemy ent_create("invader_I.mdl", vector (0, 150, 300), invader_4); //create an enemy ent_create("invader_I.mdl", vector (0, -50, 300), invader_5); //create an enemy ent_create("invader_I.mdl", vector (0, -250, 300), invader_6); //create an enemy ent_create("invader_I.mdl", vector (0, -450, 300), invader_7); //create an enemy ent_create("invader_I.mdl", vector (0, -650, 300), invader_8); //create an enemy ent_create("invader_I.mdl", vector (0, -8050, 300), invader_9); //create an enemy /* //////////////////////////////////////////////////////////////////////////////////////// ent_create("invader_II.mdl", vector (0, 750, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, 550, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, 350, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, 150, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, -50, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, -250, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, -450, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, -650, 400), invader_one); //create an enemy ent_create("invader_II.mdl", vector (0, -8050, 400), invader_one); //create an enemy //////////////////////////////////////////////////////////////////////////////////////// ent_create("invader_III.mdl", vector (0, 750, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, 550, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, 350, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, 150, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, -50, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, -250, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, -450, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, -650, 520), invader_one); //create an enemy ent_create("invader_III.mdl", vector (0, -8050, 520), invader_one); //create an enemy */ //////////////////////////////////////////////////////////////////////////////////////// ent_create("invader_III.mdl", vector (0, 0, 6520), invader_ai); //create a control ent_create("bg_black.mdl", vector (1000, 0, 0), NULL); //create the black BG vec_set(camera.x, vector (-1900, 0, 200)); // set a proper camera position }
|
|
|
Re: function not effecting neighbour
[Re: rtsgamer706]
#322585
05/07/10 23:41
05/07/10 23:41
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Ok, I guess it's time for some serious words. The code above shows, that you clearly missed some ideas and concepts of programming. Writing 9 times the same action for 9 equal entities is clearly beyond good and evil. Please don't take offense. You're a beginner and I am aware of this. It's a good thing you're continuously working on your skills. Keep that up.
The code above is just a mess. I will not debug it for you. That's athing you have to do yourself. The problems you describe above lead to the assumption that you have messed with pointers.
The best recommendation I can give: Delete the whole code. You're working beyond your skills here. Don't get frustrated. Sometimes when you code you realize that you're on the wrong track. This is a totally normal thing and happens from time to time - even to the most experienced gurus. Start again and start small. With small I mean that you should pick a very simple task, even if it appears to be trivial. Complete that task and make sure it runs without problems.
Some ideas for tasks you could work out one after another. 1. Create an empty level - without the invades, without the tank. 2. Done task nr. 1? Great. Now add the tank to it. Make sure you can move the tank from let to right and vice versa. 3. Up for task nr. 3? Add one (and only one!) invader to your level. Make sure the invader moves slowly down and ensure the tank still behaves as wanted. 4. No we're getting into the action. Add the missiles to the game. Look if you can hit the invader with the missile. For a start allow just one missile at a time. Then advance to multiple missiles at a time. 5. Made it this far? Superb. Even more action: Add a second (and I mean only one more) invader. Does everything work as expected. 6. Now the grande finale: Once you got everything to work add as many invaders as you want. If you've come this far you achieved a lot!
Other than that: Read the tutorials. I'm aware you stated you read them. Do it a second time. You're still messing around with very basic problems.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: function not effecting neighbour
[Re: rtsgamer706]
#322626
05/08/10 14:38
05/08/10 14:38
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi! Here's some more help...I hope  I see that you are having problems with the names of your entities and the concept of my or me. You have declared 3 names ENTITY* tank; ENTITY* missile; ENTITY* ene;
Yet you use me or my in all your code because you want more than one missile or more than one ene. Here's the situation. Start small as Uhrwerk said. Open an action and give me or my a name. Use that name and only that name in that code. (think small...only one) That should clear up what is being done to what. Next write only one general action for every entity. Then in the following code of the action use the name.
action xyx ()
{
ene = my;
wait (1);
ene.trigger_range = 100;
ene.flags |= (PASSABLE | BRIGHT);
....
}
Once you have a name you can control it from any function at any time. So use functions to control your names. Later, you will have to change the name and there are many ways of doings this. ex: Arrays...
Hope this helps! Ottawa  Ver 7.86.2 Pro and Lite-C
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|