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

Members Online

»
0 Active | 9 Guests
Online:

LATEST FORUM THREADS

»
warfare
CoD4 Map + Mod Releases
Voting menu on maps
CoD+UO General
Hauling 911
CoDBO3 General

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: uninitialised variable
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 11:39 am
I'm afraid my programming background has abandoned me, and I'm not sure how to fix the uninitialised variable error that I'm getting.

I'm basically trying to create an elevator script that will go to more than one floor. Not a big deal, except the elevator cab and the floors each have their own set of doors. To try to make it easier, I'm trying to create a nesting variable, eleva.

This is what I've come up with, but I must be doing something wrong. Can I even initialize a variable like this? Err, obviously I can't, or it wouldn't be giving me the error. Can I define a variable like this? If so, how do I properly initialize them?

Code:

	eleva.floor[1].ri = getent("a1ri", "targetname");
	eleva.floor[1].ro = getent("a1ro", "targetname");
	eleva.floor[1].li = getent("a1li", "targetname");
	eleva.floor[1].lo = getent("a1lo", "targetname");
	eleva.floor[2].ri = getent("a2ri", "targetname");
	eleva.floor[2].ro = getent("a2ro", "targetname");
	eleva.floor[2].li = getent("a2li", "targetname");
	eleva.floor[2].lo = getent("a2lo", "targetname");
	eleva.cab.ri = getent("acri", "targetname");
	eleva.cab.ro = getent("acro", "targetname");
	eleva.cab.li = getent("acli", "targetname");
	eleva.cab.lo = getent("aclo", "targetname");
	eleva.cab.cab = getent("acab", "targetname");
Share |
nedgerblansky
General Member
Since: Jan 28, 2005
Posts: 57
Last: Nov 9, 2007
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 01:32 pm
If you want to create a variable with fields (like .ri .ro and so on), you have to create a structure :

eleva.floor[1] = spawnstruct ();
eleva.floor[2] = spawnstruct ();
eleva.cab = spawnstruct ();
Share |
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 06:17 pm
Thank you!! I figured it was something like that. It's working like a charm! I figure those nested variables cut my code to 1/200th of the original size. [rocking]
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 08:19 pm
cool... you should post the whole script that way i could look at it. just want to see how you did it. I have wanted to try and make a elevator with multiple floors, but could never get the code right.
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 08:29 pm
Code:

towerInit()
{

	eleva = spawnstruct();
	eleva.cab = spawnstruct();
	for(i=1; i<10; i++)
	{
		eleva.floor[i] = spawnstruct();
	}


	eleva.floor[1].ri = getent("a1ri", "targetname");
	eleva.floor[1].ro = getent("a1ro", "targetname");
	eleva.floor[1].li = getent("a1li", "targetname");
	eleva.floor[1].lo = getent("a1lo", "targetname");
	eleva.floor[2].ri = getent("a2ri", "targetname");
	eleva.floor[2].ro = getent("a2ro", "targetname");
	eleva.floor[2].li = getent("a2li", "targetname");
	eleva.floor[2].lo = getent("a2lo", "targetname");
	eleva.floor[3].ri = getent("a3ri", "targetname");
	eleva.floor[3].ro = getent("a3ro", "targetname");
	eleva.floor[3].li = getent("a3li", "targetname");
	eleva.floor[3].lo = getent("a3lo", "targetname");
	eleva.floor[4].ri = getent("a4ri", "targetname");
	eleva.floor[4].ro = getent("a4ro", "targetname");
	eleva.floor[4].li = getent("a4li", "targetname");
	eleva.floor[4].lo = getent("a4lo", "targetname");
	eleva.floor[5].ri = getent("a5ri", "targetname");
	eleva.floor[5].ro = getent("a5ro", "targetname");
	eleva.floor[5].li = getent("a5li", "targetname");
	eleva.floor[5].lo = getent("a5lo", "targetname");
	eleva.floor[6].ri = getent("a6ri", "targetname");
	eleva.floor[6].ro = getent("a6ro", "targetname");
	eleva.floor[6].li = getent("a6li", "targetname");
	eleva.floor[6].lo = getent("a6lo", "targetname");
	eleva.floor[7].ri = getent("a7ri", "targetname");
	eleva.floor[7].ro = getent("a7ro", "targetname");
	eleva.floor[7].li = getent("a7li", "targetname");
	eleva.floor[7].lo = getent("a7lo", "targetname");
	eleva.floor[8].ri = getent("a8ri", "targetname");
	eleva.floor[8].ro = getent("a8ro", "targetname");
	eleva.floor[8].li = getent("a8li", "targetname");
	eleva.floor[8].lo = getent("a8lo", "targetname");
	eleva.floor[9].ri = getent("a9ri", "targetname");
	eleva.floor[9].ro = getent("a9ro", "targetname");
	eleva.floor[9].li = getent("a9li", "targetname");
	eleva.floor[9].lo = getent("a9lo", "targetname");
	eleva.cab.ri = getent("acri", "targetname");
	eleva.cab.ro = getent("acro", "targetname");
	eleva.cab.li = getent("acli", "targetname");
	eleva.cab.lo = getent("aclo", "targetname");
	eleva.cab.cab = getent("acab", "targetname");

	eleva thread elevatorThink();
}

elevatorThink()
{
	down = -1;
	up = 1;
	i = 1;

	while(1)
	{
		for(;i<9;i++)
		{
			openDoor(self, i);
			wait 3;
			closeDoor(self, i);
			moveCab(self, up);
		}
		for(;i>1;i--)
		{
			openDoor(self, i);
			wait 3;
			closeDoor(self, i);
			moveCab(self, down);
		}
	}
}

openDoor(elevator, floor)
{
	elevator.floor[floor].ri movex(62, 1);
	elevator.floor[floor].ro movex(31, 1);
	elevator.floor[floor].li movex(-62, 1);
	elevator.floor[floor].lo movex(-31, 1);
	elevator.cab.ri movex(62, 1);
	elevator.cab.ro movex(31, 1);
	elevator.cab.li movex(-62, 1);
	elevator.cab.lo movex(-31, 1);
	elevator.cab.li waittill("movedone");
		
}

closeDoor(elevator, floor)
{
	elevator.floor[floor].ri movex(-62, 1);
	elevator.floor[floor].ro movex(-31, 1);
	elevator.floor[floor].li movex(62, 1);
	elevator.floor[floor].lo movex(31, 1);
	elevator.cab.ri movex(-62, 1);
	elevator.cab.ro movex(-31, 1);
	elevator.cab.li movex(62, 1);
	elevator.cab.lo movex(31, 1);
	elevator.cab.li waittill("movedone");
		
}

moveCab(elevator, direction)
{
	elevator.cab.cab movez((136*direction), 5, 2, 2);
	elevator.cab.ri movez((136*direction), 5, 2, 2);
	elevator.cab.ro movez((136*direction), 5, 2, 2);
	elevator.cab.li movez((136*direction), 5, 2, 2);
	elevator.cab.lo movez((136*direction), 5, 2, 2);
	elevator.cab.cab waittill("movedone");
		
}


I'm still working on cleaning it up, and getting it to the point that you can select the floor you go to, but for now, it works. It goes up and then down, floor by floor. The main reason I wanted to create the structure variable is not only because of the 9 floors, but because I have 3 elevators. This way makes the code much neater and more customizable. =P

And the lo,li,ri, and ro entities are the parts of the door. It's the modern sliding door with two panels on each side. li is the left inside panel, lo is the left outside, etc.
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 08:43 pm
i see... now to select a floor you want to go to (1 to the 4th in one hit, insead of going to 2 and 3) i have see people do this for different doors to open, make different tirggers for each floor. then in your script tell it to go to that floor.

i will try and come up with a script but i havn't gotten good yet so it migh be a wile.
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Jun. 12, 2007 09:19 pm
i think i got it... or something like this. correct me please if i am wrong!

Code:
main()
{

floor1 = getent ("1", "targetname");
floor2 = getent ("2", "targetname");
floor3 = getent ("3", "targetname");

thread floor1();
thread floor2();
thread floor3();
}

floor1()
{

floor1 waittill ("trigger");

wait (1);

elevator movez (1.origin, 1); //making a script_origin at floor 1 called 1

self thread floor1();
}

floor2()
{

floor2 waittill ("trigger");

wait (1);

elevator movez (2.origin, 1); //making a script_origin at floor 2 called 2


self thread floor2();
}


floor3()
{

floor3 waittill ("trigger");

wait (1);

elevator movez (3.origin, 1); //making a script_origin at floor 3 called 3


self thread floor3();
}
 
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
WHC_Grassy
General Member
Since: Apr 20, 2005
Posts: 1426
Last: Aug 25, 2007
[view latest posts]
Level 8
Category: CoD2 Scripting
Posted: Wednesday, Jun. 13, 2007 01:53 pm
Nope, no prize yet. [biggrin]

The variables floor1,floor2,floor3 are local to the main thread.
You didnt pass them on to the new threads spawned.

To pass on the variable to another thread place the variable name at the start of the line calling the new thread, like so:

floor1 thread floor_1();

Note I changed the thread or function name as well, always use unique names for variables and functions, don't keep using the same name format or you will run into all sorts of strife.

Ok so now the variable floor1 becomes "self" in the function floor_1()
which will now look like this:
Code:

floor_1()
{
//the elevator
elevator = getent("ele","targetname");

//script origin at floor one
org1 = getent("fl1","targetname");

//now start a continual loop
 while(1)
 {

  self waittill ("trigger");
  wait (1);
  elevator moveto(org1.origin,10,2,2);

  //end of loop here
  //never re launch the same thread from inside itself, it's nasty!
  //use "while" or "for" loops instead
 }
}


Thats very basic, you would need some checking on the elevators origin if you are moving it to more than one location, and of course there is no return movement in the above example either :) But it should give you an idea on the structure and method.

Grassy
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

»