Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 65 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Bad elevator script?
cybershot
General Member
Since: Dec 29, 2005
Posts: 944
Last: Mar 4, 2018
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Friday, Mar. 25, 2016 12:41 am
This script keeps crashing and I can't figure out why. I have since separated it from the main.gcs. I put it in it's own file and I can't figure out what the issue is

******* script runtime error *******
array is not an object: (file 'maps/mp/elevator.gsc', line 18)
self waittill ("trigger");

main(){
level.elevatorDown = true; // elevator starts at bottom: true/false
level.elevatorMoving = false; // elevator is not currently moving
thread elevator_start();

}

elevator_start() {
elevator = getentarray ("elevatorswitch","targetname");
if ( isdefined(elevator) )
for (i = 0; i < elevator.size; i++)

elevator thread elevator_think();
}

elevator_think() {
while (1) {
self waittill ("trigger");
if (!level.elevatorMoving)
thread elevator_move();
}
}

elevator_move() {
elevatormodel = getent ("elevatomodel", "targetname");
level.elevatorMoving = true;
speed = 2;
height = 300;
wait (1);
if (level.elevatorDown) { // moves to top
elevatormodel playsound ("elevator1"); // sound definition for soundaliases.csv
wait (1); // wait a second to hear the motor start and then start the movement of the lift - feels more realistic
elevatormodel moveZ (height, speed);
elevatormodel waittill ("movedone");
level.elevatorDown = false;

} else { // moves to bottom
elevatormodel playsound ("elevator1"); // sound definition for soundaliases.csv
wait (1); // wait a second to hear the motor start and then start the movement of the lift - feels more realistic
elevatormodel moveZ (height - (height * 2), speed);
elevatormodel waittill ("movedone");
level.elevatorDown = true;
}
level.elevatorMoving = false;

}
Share |
dundy
General Member
Since: Dec 14, 2004
Posts: 768
Last: Nov 1, 2020
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Friday, Mar. 25, 2016 10:47 pm
This one should work.
Code:
main() {   level.elevator_1Down = true;   level.elevator_1Moving = false;   thread elevator_1_start(); }   elevator_1_start() {   elevator_1 = getentarray ("switch_1","targetname");   if ( isdefined(elevator_1) )   for (i = 0; i < elevator_1.size; i++)   elevator_1[i] thread elevator_1_think(); }   elevator_1_think() {   while (1)   {    self waittill ("trigger");    if (!level.elevator_1Moving)    thread elevator_1_move();   } }   elevator_1_move() {   elevator_1model = getent ("elevator_1", "targetname");   level.elevator_1Moving = true;   speed = 10;   height =-581;   if (level.elevator_1Down)    {    elevator_1model playsound ("elevator_1");    elevator_1model movez (height, speed);    elevator_1model waittill ("movedone");    level.elevator_1Down = false;   }   else   {    elevator_1model playsound ("elevator_1");    elevator_1model movez (height - (height * 2), speed);    elevator_1model waittill ("movedone");    level.elevator_1Down = true;   }   level.elevator_1Moving = false; }
Share |
DeekCiti
General Member
Since: Mar 13, 2008
Posts: 1293
Last: Jul 9, 2016
[view latest posts]
Level 8
Category: CoD2 Scripting
Posted: Tuesday, Mar. 29, 2016 03:13 am
It crashed I believe because you didn't carry the array through.

Try this, I edited one line. And cleaned up the code so I could read it better. Brackets are important. They separate functions/sets/scopes etc. and it makes reading the code so much easier aside from other people trying to read it. In most cases, it can run without them, but it's ugly. I threw up twice in my mouth, but I swallowed it, no worries. [thumbs_up]

Code:

main()
{
	level.elevatorDown = true; // elevator starts at bottom: true/false
	level.elevatorMoving = false; // elevator is not currently moving
	thread elevator_start();
}

elevator_start()
{
	elevator = getentarray ("elevatorswitch","targetname");
	if ( isdefined(elevator) )
	{
		for (i = 0; i < elevator.size; i++)
		{
			elevator[i] thread elevator_think();  //EDITED LINE
		}
	}
}

elevator_think()
{
	while (1)
	{
		self waittill ("trigger");
		if (!level.elevatorMoving)
		{
			thread elevator_move();
		}
	}
}

elevator_move() 
{
	elevatormodel = getent ("elevatomodel", "targetname");
	level.elevatorMoving = true;
	speed = 2;
	height = 300;
	wait (1);
	if (level.elevatorDown) // moves to top
	{
		elevatormodel playsound ("elevator1"); // sound definition for soundaliases.csv
		wait (1); // wait a second to hear the motor start and then start the movement of the lift - feels more realistic
		elevatormodel moveZ (height, speed);
		elevatormodel waittill ("movedone");
		level.elevatorDown = false;
	}
	else  // moves to bottom
	{
		elevatormodel playsound ("elevator1"); // sound definition for soundaliases.csv
		wait (1); // wait a second to hear the motor start and then start the movement of the lift - feels more realistic
		elevatormodel moveZ (height - (height * 2), speed);
		elevatormodel waittill ("movedone");
		level.elevatorDown = true;
	}
	level.elevatorMoving = false;
}
Share |
dundy
General Member
Since: Dec 14, 2004
Posts: 768
Last: Nov 1, 2020
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Mar. 29, 2016 05:11 pm
I just copy and paste into the code function did not check how it came out. My bad.[cool]
Share |
cybershot
General Member
Since: Dec 29, 2005
Posts: 944
Last: Mar 4, 2018
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Tuesday, Mar. 29, 2016 10:32 pm
DeekCiti writes...
Quote:
In most cases, it can run without them, but it's ugly. I threw up twice in my mouth, but I swallowed it, no worries. [thumbs_up]



LOL,

it worked. Thank you DeekCiti. This code was not mine. I found it in the forums here and thought I would give it a try. I had another script that was very basic that worked for going up but I liked this one better for the other options that were already in there. I understand now why it didn't work. Your code is clean and easy to read.
Share |
DeekCiti
General Member
Since: Mar 13, 2008
Posts: 1293
Last: Jul 9, 2016
[view latest posts]
Level 8
Category: CoD2 Scripting
Posted: Wednesday, Mar. 30, 2016 03:58 am
Yeah, I figured you found it somewhere only cause most of them use the same variables and or method names. Nothing wrong with taking one someone posted.

There's actually more stuff you can do with that script to make it easier to configure, or clean it up, but it works and that's all that matters. And if you aren't already trying to add it in, then you probably don't need it anyway.

Glad it worked though, wasn't sure if I missed a bracket or not.

And a good way to work is to always separate your scripts. It makes finding things easier and debugging problems easier. If you have one .gsc with every script in it, you could not only run into conflicts but how you going to find anything without using ctrl+f or the scroll bar like candy. You should separate them and just call them from the main .gsc. Saves headaches. Now I'm just blabberin' [duh]
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»