Jump to content

Home

Qui-Gon's Script Shack


Qui-Gon Glenn

Recommended Posts

  • Replies 352
  • Created
  • Last Reply

Thought I'd drop in and say hi with a script to look at.

 

This mostly came from me looking over some HK factory scripts and realizing just how inefficient they were.

 

I had these three separate scripts

 

a_disthk51

Show spoiler
(hidden content - requires Javascript to show)
void main(){

object oHk51cs = GetObjectByTag("hk51cs", 0);
string string1 = "hk51_1";
int int3 = 0;
object object1 = GetObjectByTag(string1, int3);

if(GetGlobalNumber("299TEL_HK51") < 2){
	if(GetGlobalNumber("299TEL_HK51_Active") < 2){

		SetGlobalNumber("299TEL_HK51_Active", 3);

	}


	if(GetGlobalNumber("299TEL_HK51_Core") == 1){
		while ((int3 < 21)) {
			SignalEvent(object1, EventUserDefined(1003));
			(int3++);
			AssignCommand(object1, ActionPlayAnimation(0,1.0));
			object1 = GetObjectByTag(string1, int3);
		}
		AssignCommand(oHk51cs, ActionPlayAnimation(0,1.0));
		ExecuteScript("a_move51line", GetArea(OBJECT_SELF), 0xFFFFFFFF);

	}
	else{
		int3 = 0;
		while ((int3 < 21)) {
			if(int3 < 17){
				ChangeToStandardFaction(object1, 3);
				SignalEvent(object1, EventUserDefined(1003));
			}
				(int3++);
				AssignCommand(object1, ActionPlayAnimation(0,1.0));
				object1 = GetObjectByTag(string1, int3);
		}
		AssignCommand(oHk51cs, ActionPlayAnimation(0,1.0));
		ExecuteScript("a_move51disp", GetArea(OBJECT_SELF), 0xFFFFFFFF);
	}
}
}

a_move51line

Show spoiler
(hidden content - requires Javascript to show)
void main() {
int int1 = 0;
string string1 = "hk51_1";
object object1 = GetObjectByTag(string1, int1);
string sWay1 = IntToString(int1);
while ( (object1 != OBJECT_INVALID) ) {
               AssignCommand(object1, JumpToObject(GetObjectByTag("WP_HK51_LINE_" + sWay1, 0), 1));
	(int1++);
	object1 = GetObjectByTag(string1, int1);
	sWay1 = IntToString(int1);

}

object object3 = GetObjectByTag("hk51cs", 0);
AssignCommand(object3, JumpToObject(GetObjectByTag("WP_HK51_LINE_L", 0), 1));
}

a_move51disp

Show spoiler
(hidden content - requires Javascript to show)
void main() {
int int1 = 0;
string string1 = "hk51_1";
object object1 = GetObjectByTag(string1, int1);
string sWay1 = IntToString(int1);
while ( (object1 != OBJECT_INVALID) ) {
               AssignCommand(object1, JumpToObject(GetObjectByTag("WP_HK51_NME_" + sWay1), 1));
	(int1++);
	object1 = GetObjectByTag(string1, int1);
	sWay1 = IntToString(int1);

}

object object3 = GetObjectByTag("hk51cs", 0);
AssignCommand(object3, JumpToObject(GetObjectByTag("WP_HK51_NME_L", 0), 1));

}

to distribute some HK51 units around the HK factory based on their behavior cores.

 

I just had to rewrite the code and I came up with this:

I put some comments in too to make it user-friendly. ;)

Shows off some nice examples of how to use while loops and methods.

 

Show spoiler
(hidden content - requires Javascript to show)
/*If you're defining any methods, be sure you declare them up here first
*before using them in the main code.
*You can put all of the code up here if you want, but I find it easier
*to put it down below.
*/

string factWP();

//Any variables that are going to be used in more than one method, declare them here, but initialize in the method.
int nGlobal;

void main() {

/*Declare all of your variables at the top up here
*It doesn't matter what order you do them in, but
*it helps to have them in a certain order, especially
*if some are dependent on other type variables
*/

//Integer variables
int nObjectNum = 0;
int nGlobal = GetGlobalNumber("299TEL_HK51_Core");

//String variables
string sTag = "hk51_1";
string sWPName;

//Notice how sWPNum is dependent on nObjectNum existing
string sWPNum = IntToString(nObjectNum);

object oHk51cs = GetObjectByTag("hk51cs", 0);
object oHK51Object = GetObjectByTag(sTag, 0);


/*This runs a loop and keeps running through all of the objects
*in the area that fit the oHK51Object specifications.
*/
while (oHK51Object != OBJECT_INVALID){

//Always ClearAllActions() before trying to assign new actions
	AssignCommand(oHK51Object, ClearAllActions());

//DelayCommands are essential to the sequencing process
//If you try to assign commands all at once, they most likely won't fire
	DelayCommand(1.0, AssignCommand(oHK51Object, ActionJumpToObject(GetObjectByTag(factWP() + sWPNum, 0))));
	DelayCommand(2.5, AssignCommand(oHK51Object, ActionPlayAnimation(19, 1.0, 0.0)));

/*It's often helpful to send debug information to your feedback screen so you know what's going on*/
	SendMessageToPC(GetFirstPC(), factWP() + sWPNum + " is what's showing.");

//Any type of loop needs to be incremented if you want a possibility of ever exiting the loop
	(nObjectNum++);
	oHK51Object = GetObjectByTag(sTag, nObjectNum);
	sWPNum = IntToString(nObjectNum);

//Then the loop starts over!
}

AssignCommand(oHk51cs, JumpToObject(GetObjectByTag(factWP() + "L", 0), 1));
DelayCommand(1.0, AssignCommand(oHk51cs, ActionPlayAnimation(19, 1.0, 0.0)));

}

string factWP(){
if(nGlobal == 1){
	return "WP_HK51_LINE_";
}
else{
	return "WP_HK51_NME_";
}

}

 

What's my point behind this? Well, the point is the more you know about scripting/programming, the more efficient your scripts can be. Same functionality, WAAAAY more concise.

 

Expect me to drop in more often ;)

Link to comment
Share on other sites

But what is a method exactly?

 

To put it simply, it's a way of simplifying and organizing your code by segmenting it into different parts.

 

All of the same syntax applies, it's just WAAAY easier to read in some cases.

 

Let's say we have an object that we want to do a series of commands. Let's say we want a Jedi to Force shock a Sith.

 

That script might look like this:

Show spoiler
(hidden content - requires Javascript to show)
void main(){

object oJedi = GetObjectByTag("JediKnight");
object oEnemy = GetNearestObjectByTag("Sith");

AssignCommand(oJedi, ActionUseSpellOnObject(FORCE_POWER_SHOCK, oEnemy);

}

Fair enough, but what if we want the Jedi to use more than one spell in a sequence? That would look something like this:

Show spoiler
(hidden content - requires Javascript to show)
void main(){

object oJedi = GetObjectByTag("JediKnight");
object oEnemy = GetNearestObjectByTag("Sith");

AssignCommand(oJedi, ActionUseSpellOnObject(FORCE_POWER_SHOCK, oEnemy);
DelayCommand(1.0, AssignCommand(oJedi, ActionUseSpellOnObject(FORCE_POWER_PLAGUE, oEnemy));
}

*Notice the use of DelayCommand. You CANNOT assign multiple commands in one instance.

Fair enough again, but what if we have another Jedi join in on the Sith torture? Would we have to keep adding AssignCommand calls? No, not necessarily. Check out the following code:

 

Show spoiler
(hidden content - requires Javascript to show)
void torture(object obj, object victim);

void main(){

object oJedi = GetObjectByTag("JediKnight");
object oJedi2 = GetObjectByTag("JediMaster");
object oJedi3 = GetObjectByTag("JediPadawan");
object oEnemy = GetNearestObjectByTag("Sith");

torture(oJedi, oEnemy);
torture(oJedi2, oEnemy);
torture(oJedi3, oEnemy);
}

void torture(object obj, object victim){
AssignCommand(obj, ActionUseSpellOnObject(FORCE_POWER_SHOCK, victim);
DelayCommand(1.0, AssignCommand(obj, ActionUseSpellOnObject(FORCE_POWER_PLAGUE, victim));	
}

 

 

For every instance of torture in void main, it will actually read the code in void torture(), substituting the parameters for whichever objects you write in! Cool huh?

 

Now, not ever method has to be void main() or void whatever(), you can actually write something like:

 

int countMyFoes()

string getMyName()

object getWeakestEnemy()

 

but that's a lesson for another time...

Link to comment
Share on other sites

^^^ nice use and explanation of a "subroutine"

 

The vanilla hk code was ridiculous.... Looked like a struggling CS student who barely got his homework turned in on time!

 

I like the teaser at the end.... Data-type functions I will be glad to see - I have only ever used void or int types. Thanks VP!

Link to comment
Share on other sites

Hey again...got a problem I really can't figure out.

 

Now, I'm no programmer. I've never had any school or anything for programming. What I know of it is all from TSL scripting, out of necessity.

...because I want things to happen, or not happen. :)

 

What I want to happen is not have the player recieve a default lightsaber when constructing thier saber for Jedi training, but one of my custom hilt models with it's own tag/template.

I believe I have the right script for the event. k_pdan_saber16..

and when I decompiled it and looked at it I thought, "oh, brilliant. i'll just change the tag's for the string stringGLOB_4, 5 and 6.".....

 

Nope. Not gonna happen. You get nothing.

 

After messing with it and trying different things for three hours I had to stop before I started wrecking stuff.

 

// Globals
int intGLOB_1 = 1;
int intGLOB_2 = 2;
int intGLOB_3 = 3;
int intGLOB_4 = 4;
int intGLOB_5 = 5;
int intGLOB_6 = 6;
int intGLOB_7 = 3;
int intGLOB_8 = 4;
int intGLOB_9 = 5;
int intGLOB_10 = 6;
int intGLOB_11 = 7;
int intGLOB_12 = 1;
int intGLOB_13 = 2;
int intGLOB_14 = 3;
int intGLOB_15 = 4;
int intGLOB_16 = 5;
int intGLOB_17 = 6;
int intGLOB_18 = 7;
int intGLOB_19 = 8;
int intGLOB_20 = 9;
int intGLOB_21 = 10;
int intGLOB_22 = 11;
int intGLOB_23 = 12;
int intGLOB_24 = 13;
int intGLOB_25 = 14;
int intGLOB_26 = 15;
int intGLOB_27 = 16;
int intGLOB_28 = 17;
int intGLOB_29 = 18;
int intGLOB_30 = 19;
int intGLOB_31 = 20;
int intGLOB_32 = 21;
int intGLOB_33 = 22;
int intGLOB_34 = 23;
int intGLOB_35 = 24;
int intGLOB_36 = 25;
int intGLOB_37 = 26;
int intGLOB_38 = 27;
int intGLOB_39 = 28;
int intGLOB_40 = 29;
int intGLOB_41 = 30;
int intGLOB_42 = 59;
int intGLOB_43 = 0;
int intGLOB_44 = 1;
int intGLOB_45 = 2;
int intGLOB_46 = 29;
int intGLOB_47 = 30;
int intGLOB_48 = 34;
int intGLOB_49 = 35;
int intGLOB_50 = 36;
int intGLOB_51 = 37;
int intGLOB_52 = 38;
int intGLOB_53 = 39;
int intGLOB_54 = 41;
int intGLOB_55 = 42;
int intGLOB_56 = 46;
int intGLOB_57 = 47;
int intGLOB_58 = 15;
int intGLOB_59 = 10;
int intGLOB_60 = 5;
int intGLOB_61 = 2;
int intGLOB_62;
int intGLOB_63;
int intGLOB_64;
object objectGLOB_1;
int intGLOB_65;
int intGLOB_66;
int intGLOB_67;
int intGLOB_68;
int intGLOB_69;
int intGLOB_70;
int intGLOB_71 = 1;
int intGLOB_72 = 2;
int intGLOB_73 = 3;
int intGLOB_74 = 20;
int intGLOB_75 = 21;
int intGLOB_76 = 22;
int intGLOB_77 = 23;
int intGLOB_78 = 24;
int intGLOB_79 = 25;
int intGLOB_80 = 26;
int intGLOB_81 = 27;
int intGLOB_82 = 28;
int intGLOB_83 = 31;
int intGLOB_84 = 32;
int intGLOB_85 = 33;
int intGLOB_86 = 40;
int intGLOB_87 = 43;
int intGLOB_88 = 44;
int intGLOB_89 = 45;
int intGLOB_90 = 48;
int intGLOB_91 = 49;
int intGLOB_92 = 50;
int intGLOB_93 = 51;
int intGLOB_94 = 52;
int intGLOB_95 = 53;
int intGLOB_96 = 54;
int intGLOB_97 = 55;
int intGLOB_98 = 56;
int intGLOB_99 = 57;
int intGLOB_100 = 58;
int intGLOB_101 = 60;
int intGLOB_102 = 61;
int intGLOB_103 = 62;
int intGLOB_104 = 63;
int intGLOB_105 = 64;
int intGLOB_106 = 65;
int intGLOB_107 = 66;
int intGLOB_108 = 67;
int intGLOB_109 = 68;
int intGLOB_110 = 69;
int intGLOB_111 = 70;
int intGLOB_112 = 71;
int intGLOB_113 = 72;
int intGLOB_114 = 1;
int intGLOB_115 = 2;
int intGLOB_116 = 3;
int intGLOB_117 = 4;
int intGLOB_118 = 0;
int intGLOB_119 = 1;
int intGLOB_120 = 2;
int intGLOB_121 = 3;
int intGLOB_122 = 4;
int intGLOB_123 = 5;
int intGLOB_124 = 6;
int intGLOB_125 = 7;
int intGLOB_126 = 8;
int intGLOB_127 = 9;
int intGLOB_128 = 10;
int intGLOB_129 = 11;
int intGLOB_130 = 12;
int intGLOB_131 = 13;
int intGLOB_132 = 14;
int intGLOB_133 = 15;
int intGLOB_134 = 16;
int intGLOB_135 = 17;
int intGLOB_136 = 18;
int intGLOB_137 = 19;
int intGLOB_138 = 1100;
int intGLOB_139 = (-6);
int intGLOB_140 = (-5);
int intGLOB_141 = (-4);
int intGLOB_142 = (-2);
int intGLOB_143 = (-1);
int intGLOB_144 = 0;
int intGLOB_145 = 4;
int intGLOB_146 = 1;
int intGLOB_147 = 7;
int intGLOB_148 = 1;
int intGLOB_149 = 2;
int intGLOB_150 = 3;
int intGLOB_151 = 1;
int intGLOB_152 = 2;
int intGLOB_153 = 3;
int intGLOB_154 = 4;
int intGLOB_155 = 5;
int intGLOB_156 = 6;
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
string stringGLOB_4 = "g_w_lghtsbr01";
string stringGLOB_5 = "g_w_lghtsbr03"; 
string stringGLOB_6 = "g_w_lghtsbr04";
            string stringGLOB_7 = "dan_wanderhound";

// Prototypes
object sub1();

object sub1() {
object oPC = GetFirstPC();
object object3;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0);
int nGlobal = GetGlobalNumber("DAN_PATH_STATE");
if ((nGlobal > 0)) {
	if ((nGlobal == intGLOB_148)) {
		object3 = CreateItemOnObject(stringGLOB_4, oPC, 1);
	}
	else {
		if ((nGlobal == intGLOB_149)) {
			object3 = CreateItemOnObject(stringGLOB_6, oPC, 1);
		}
		else {
			if ((nGlobal == intGLOB_150)) {
				object3 = CreateItemOnObject(stringGLOB_5, oPC, 1);
			}
		}
	}
}
if (GetIsObjectValid(object3)) {
	DelayCommand(0.1, AssignCommand(oPC, ActionEquipItem(object3, 4, 0)));
}
return object3;
}

void main() {
object object1 = sub1();
ShowUpgradeScreen(object1);
}

 

object3 depends on what globals were set during the questioning, as you know. (intGLOB_148-150.)

Why can't I put my "pc_lghtsbr_001/002/003" tags in instead of "g_w_lghtsbr0x" and get my custom saber hilt?

 

Thankyou for any advice and knowledge you could bestow.

-QDJ

Link to comment
Share on other sites

Ok... It seems to me that there should not be an issue with how you are going about this. I guess I would like to see the code that you created, vs. the vanilla code posted here. If I understand you correctly, you modified these lines:

string stringGLOB_4 = "g_w_lghtsbr01"; [color=darkorange]  <-- Subbing "pc_lghtsbr_001"?[/color]
string stringGLOB_5 = "g_w_lghtsbr03";
string stringGLOB_6 = "g_w_lghtsbr04";

If this is where you performed your substitutions, I would think everything should work just fine. It is simple variable substitution, and the only thing you should have to change are the tags.... as you said.

 

I am wondering... Did you make this change, and then not use a fresher save where that script had not been called yet? It may be as simple as module memory blocking your new version from firing.

 

If this is not the simple solution, hopefully one of our more skilled contributors here in the shack can give you a heads up!

 

EDIT: This may sound stupid. It may be stupid. The filename lengths are different.... 13 chars for "g_w_lghtsbr01" versus 14 chars for "pc_lghtsbr_001". This shouldn't matter, as long as it is less than 16 chars.... but stranger things have been the cause of issue in these games!

Link to comment
Share on other sites

Might want to initialize the variable inside of void sub1(). You can declare it up there, but give it the value in the method.

 

Show spoiler
(hidden content - requires Javascript to show)
string sTag;

void sub1(){

sTag = "Lightsaber01";

etc......

 

I hope that helps.... sometimes there's not a good reason for why some of this stuff happens. It's not a very solid system I guess.

 

and interesting enough, that HK factory code was before I had taken any programming class, so I guess that deduction would make sense, QGG......

 

Filename/Tag length might do it too though.. yeah that's probably it.

Link to comment
Share on other sites

I am wondering... Did you make this change, and then not use a fresher save where that script had not been called yet? It may be as simple as module memory blocking your new version from firing.

 

I'm 99% sure I tried it again from a save back at Davik's.

1% of me isn't sure cause my short term memory is completely gone.

 

 

EDIT: This may sound stupid. It may be stupid. The filename lengths are different.... 13 chars for "g_w_lghtsbr01" versus 14 chars for "pc_lghtsbr_001". This shouldn't matter, as long as it is less than 16 chars.... but stranger things have been the cause of issue in these games

 

No, not stupid at al Glenn. But already thought of that and changed the tags of my uti's to p_c_lghtsbr01/02/03 and reedited the 2da to match..recompiled the script and the module and started again at Davik's. (I think)...still no dice...even put my saber and crystal uti's in the module file with it..

hold on..new post.

Link to comment
Share on other sites

Might want to initialize the variable inside of void sub1(). You can declare it up there, but give it the value in the method

 

Kay, not sure what you mean, VP.

void sub1()? you mean object sub1()?

 

so you mean declare "pc_lghtsbr_xxx" in object sub1()..? like replace object3?

 

uugh. sorry confused...

what would it actually look like VP?

 

Oh and yes, QGG, I just subbed the g_w_lghtsbr tags for pc_lghtsbr_xxx, but maybe I should try it again with exactly 13 character tags...I always thought they just needed to be under 16..

Link to comment
Share on other sites

Concerning this section of code:

 

Show spoiler
(hidden content - requires Javascript to show)
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
string stringGLOB_4 = "g_w_lghtsbr01";
string stringGLOB_5 = "g_w_lghtsbr03"; 
string stringGLOB_6 = "g_w_lghtsbr04";
            string stringGLOB_7 = "dan_wanderhound";

// Prototypes
object sub1();

object sub1() {
object oPC = GetFirstPC();
object object3;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0)

 

make these changes:

 

Show spoiler
(hidden content - requires Javascript to show)
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
[color="DarkOrange"]string stringGLOB_4;
string stringGLOB_5; 
string stringGLOB_6;[/color]
            string stringGLOB_7 = "dan_wanderhound";

// Prototypes
object sub1();

object sub1() {
[color="DarkOrange"]stringGLOB_4 = "g_w_lghtsbr01";
stringGLOB_5 = "g_w_lghtsbr03"; 
stringGLOB_6 = "g_w_lghtsbr04";[/color]
object oPC = GetFirstPC();
object object3;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0)

 

I don't know if it will help, but it worked on my HK factory code.

Link to comment
Share on other sites

Concerning this section of code:

 

Show spoiler
(hidden content - requires Javascript to show)
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
string stringGLOB_4 = "g_w_lghtsbr01";
string stringGLOB_5 = "g_w_lghtsbr03"; 
string stringGLOB_6 = "g_w_lghtsbr04";
            string stringGLOB_7 = "dan_wanderhound";

// Prototypes
object sub1();

object sub1() {
object oPC = GetFirstPC();
object object3;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0)

 

make these changes:

 

Show spoiler
(hidden content - requires Javascript to show)
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
[color="DarkOrange"]string stringGLOB_4;
string stringGLOB_5; 
string stringGLOB_6;[/color]
            string stringGLOB_7 = "dan_wanderhound";

// Prototypes
object sub1();

object sub1() {
[color="DarkOrange"]stringGLOB_4 = "g_w_lghtsbr01";
stringGLOB_5 = "g_w_lghtsbr03"; 
stringGLOB_6 = "g_w_lghtsbr04";[/color]
object oPC = GetFirstPC();
object object3;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0)

 

I don't know if it will help, but it worked on my HK factory code.

 

ok i see. and this wouldn't mess with the variable list up top?

 

then just replace default saber tags with mine in object sub1() ?

Link to comment
Share on other sites

and interesting enough, that HK factory code was before I had taken any programming class, so I guess that deduction would make sense, QGG......

 

Oops... I did not know that those were two different versions of your own code :p I was not meaning a dis! As it is though, the difference between the code samples obviously shows a much deeper understanding of algorithm in the latter - which does make sense, as you have been working your tail off :D

 

@KDJ: yeah, initializing the value of the variable inside of that subroutine may do the trick. It shouldn't be that way - there is nothing invalid in trying to go about things the same way the original version did, and it would actually seem to be the best way to go about it. However, this is a case of us giving the OG programmers too much credit - their stuff breaks just as often, if not more often, than our community-made code does.

Link to comment
Share on other sites

Oops... I did not know that those were two different versions of your own code :p I was not meaning a dis! As it is though, the difference between the code samples obviously shows a much deeper understanding of algorithm in the latter - which does make sense, as you have been working your tail off :D

 

Well, it's not like the original code is assembled the greatest fashion... Seriously, talking about endless if and else statements when a simple switch/case would be so much more efficient!

 

yeah, initializing the value of the variable inside of that subroutine may do the trick. It shouldn't be that way - there is nothing invalid in trying to go about things the same way the original version did, and it would actually seem to be the best way to go about it. However, this is a case of us giving the OG programmers too much credit - their stuff breaks just as often, if not more often, than our community-made code does.

 

A side effect of the engine just not handling the scripts very well. I have had scenarios where the declaration of the object makes all the difference, and while statements simply don't run, despite the correct programming.

Link to comment
Share on other sites

A side effect of the engine just not handling the scripts very well. I have had scenarios where the declaration of the object makes all the difference, and while statements simply don't run, despite the correct programming.

The last part of this bugs me.... You are saying that in many cases, while/do loops have failed to run/function properly, despite as you say correct programming and successful compilation?

 

That would explain some issues I have had....

 

I agree wholeheartedly on the superior structure of a case/switch over the endless nested if statements... And then I remember JCarter426 a while back stating that he feels the switch gets ignored by the engine fairly often. :giveup:

 

This all comes back to the first sentence of your quote.... How sad but true.

 

Nevertheless, we plow on!

 

***

 

@JCarter426: Just wanted to let you know that, despite how confusing I was being with my script issue in the j7 mod, you did illuminate one obvious mistake I was making! I was trying to spawn the container in the wrong module... which may have caused other issues as well. I am going to revisit it today, and I will return with some update. It is going to be a test case for the case/switch, as I am using it to put class-specific loot into the new container.

 

***

 

@QDJ- If you got it working, let us know! Otherwise, perhaps post the code you have that is compiling yet still failing? Another set of eyes can be priceless :)

Link to comment
Share on other sites

Sad, but true. Actually, the while statements would work, but they would stop prematurely without any particular reason. When I divided the while statement up into separate segments though, it seemed to work, and that really threw me off :/ because it shouldn't make a difference really.

 

Interesting observation from JCarter, considering the switch statement always works for me. In fact, it works so much better than if/else statements that all of the MVI modules use an onEnter script using a global in a switch statement. I was getting some weird results with if/else such as some statements would be completely overlooked despite the correct syntax.

Link to comment
Share on other sites

For the record, I prefer switches as well - I almost never write a script without them. :D But it's not that they're ignored, exactly... it's more like what VarsityPuppet said - how you declare the objects matters even when it shouldn't (or it seems like it shouldn't, anyway). When I declare objects inside a case, after spawning them in another case, sometimes the game just doesn't recognize them. Sometimes I've switched to ifs and that worked, although I've had other problems with ifs. Sometimes I've decided to just not declare a variable and used GetObjectByTag over and over, and that worked. Sometimes I've split it into two different scripts, both with their own switches, and that worked. I <3 subroutines too, by the way. Sometimes I've used a subroutine and that worked!

Link to comment
Share on other sites

It can be tedious, but if you declare your variables outside the switch, then initialize/assign values in the switch statement, it oftentimes works waaay better, if not all the time.

 

If yoou're using some of the same variables in subroutines, I've declared varialbes outside of void main and it worked, although it didn't seem to want to work with integers..

Link to comment
Share on other sites

Ok, for this K1script I was working on (not this week) I did actually get it functioning(sort of), but in the worst possible way.

 

What I eventually ended up doing was making a new sub, and just bypassed it's int_glob and stringGLOB list altogether. So, really I let it do what it was going to do with creating the default sabers. then in my object sub2(), I created my sabers and equipped them just like they had. Except mine went straight for the Global Number "DAN_PATH_STATE" check, and if 1 = create blue, 2 = create yellow, 3 = create green. Then in the void main () I destroyed the default saber and said ShowUpgradeScreen with my new object...but that was the only part that didn't work.

 

I think I could get it to work if I just re-wrote their object sub1() like I wrote my object sub2()..

Will post when (if) I get it working..

 

 

Ok, Im back...So what I'm proposing would look like this..

 

// Globals
int intGLOB_1 = 1;
int intGLOB_2 = 2;
int intGLOB_3 = 3;
int intGLOB_4 = 4;
int intGLOB_5 = 5;
int intGLOB_6 = 6;
int intGLOB_7 = 3;
int intGLOB_8 = 4;
int intGLOB_9 = 5;
int intGLOB_10 = 6;
int intGLOB_11 = 7;
int intGLOB_12 = 1;
int intGLOB_13 = 2;
int intGLOB_14 = 3;
int intGLOB_15 = 4;
int intGLOB_16 = 5;
int intGLOB_17 = 6;
int intGLOB_18 = 7;
int intGLOB_19 = 8;
int intGLOB_20 = 9;
int intGLOB_21 = 10;
int intGLOB_22 = 11;
int intGLOB_23 = 12;
int intGLOB_24 = 13;
int intGLOB_25 = 14;
int intGLOB_26 = 15;
int intGLOB_27 = 16;
int intGLOB_28 = 17;
int intGLOB_29 = 18;
int intGLOB_30 = 19;
int intGLOB_31 = 20;
int intGLOB_32 = 21;
int intGLOB_33 = 22;
int intGLOB_34 = 23;
int intGLOB_35 = 24;
int intGLOB_36 = 25;
int intGLOB_37 = 26;
int intGLOB_38 = 27;
int intGLOB_39 = 28;
int intGLOB_40 = 29;
int intGLOB_41 = 30;
int intGLOB_42 = 59;
int intGLOB_43 = 0;
int intGLOB_44 = 1;
int intGLOB_45 = 2;
int intGLOB_46 = 29;
int intGLOB_47 = 30;
int intGLOB_48 = 34;
int intGLOB_49 = 35;
int intGLOB_50 = 36;
int intGLOB_51 = 37;
int intGLOB_52 = 38;
int intGLOB_53 = 39;
int intGLOB_54 = 41;
int intGLOB_55 = 42;
int intGLOB_56 = 46;
int intGLOB_57 = 47;
int intGLOB_58 = 15;
int intGLOB_59 = 10;
int intGLOB_60 = 5;
int intGLOB_61 = 2;
int intGLOB_62;
int intGLOB_63;
int intGLOB_64;
object objectGLOB_1;
int intGLOB_65;
int intGLOB_66;
int intGLOB_67;
int intGLOB_68;
int intGLOB_69;
int intGLOB_70;
int intGLOB_71 = 1;
int intGLOB_72 = 2;
int intGLOB_73 = 3;
int intGLOB_74 = 20;
int intGLOB_75 = 21;
int intGLOB_76 = 22;
int intGLOB_77 = 23;
int intGLOB_78 = 24;
int intGLOB_79 = 25;
int intGLOB_80 = 26;
int intGLOB_81 = 27;
int intGLOB_82 = 28;
int intGLOB_83 = 31;
int intGLOB_84 = 32;
int intGLOB_85 = 33;
int intGLOB_86 = 40;
int intGLOB_87 = 43;
int intGLOB_88 = 44;
int intGLOB_89 = 45;
int intGLOB_90 = 48;
int intGLOB_91 = 49;
int intGLOB_92 = 50;
int intGLOB_93 = 51;
int intGLOB_94 = 52;
int intGLOB_95 = 53;
int intGLOB_96 = 54;
int intGLOB_97 = 55;
int intGLOB_98 = 56;
int intGLOB_99 = 57;
int intGLOB_100 = 58;
int intGLOB_101 = 60;
int intGLOB_102 = 61;
int intGLOB_103 = 62;
int intGLOB_104 = 63;
int intGLOB_105 = 64;
int intGLOB_106 = 65;
int intGLOB_107 = 66;
int intGLOB_108 = 67;
int intGLOB_109 = 68;
int intGLOB_110 = 69;
int intGLOB_111 = 70;
int intGLOB_112 = 71;
int intGLOB_113 = 72;
int intGLOB_114 = 1;
int intGLOB_115 = 2;
int intGLOB_116 = 3;
int intGLOB_117 = 4;
int intGLOB_118 = 0;
int intGLOB_119 = 1;
int intGLOB_120 = 2;
int intGLOB_121 = 3;
int intGLOB_122 = 4;
int intGLOB_123 = 5;
int intGLOB_124 = 6;
int intGLOB_125 = 7;
int intGLOB_126 = 8;
int intGLOB_127 = 9;
int intGLOB_128 = 10;
int intGLOB_129 = 11;
int intGLOB_130 = 12;
int intGLOB_131 = 13;
int intGLOB_132 = 14;
int intGLOB_133 = 15;
int intGLOB_134 = 16;
int intGLOB_135 = 17;
int intGLOB_136 = 18;
int intGLOB_137 = 19;
int intGLOB_138 = 1100;
int intGLOB_139 = (-6);
int intGLOB_140 = (-5);
int intGLOB_141 = (-4);
int intGLOB_142 = (-2);
int intGLOB_143 = (-1);
int intGLOB_144 = 0;
int intGLOB_145 = 4;
int intGLOB_146 = 1;
int intGLOB_147 = 7;
int intGLOB_148 = 1;
int intGLOB_149 = 2;
int intGLOB_150 = 3;
int intGLOB_151 = 1;
int intGLOB_152 = 2;
int intGLOB_153 = 3;
int intGLOB_154 = 4;
int intGLOB_155 = 5;
int intGLOB_156 = 6;
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
string stringGLOB_4 = "g_w_lghtsbr01";
string stringGLOB_5 = "g_w_lghtsbr03"; 
string stringGLOB_6 = "g_w_lghtsbr04";
            string stringGLOB_7 = "dan_wanderhound";

// Prototypes
object sub1();

object sub1() {
object oPC = GetFirstPC();
object oSbr;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0);

if (GetGlobalNumber("DAN_PATH_STATE") == 1) {

		oSbr = CreateItemOnObject("pc_lghtsbr_001", oPC, 1);
	}
	else {
		if (GetGlobalNumber("DAN_PATH_STATE") == 2) {
			oSbr = CreateItemOnObject("pc_lghtsbr_002", oPC, 1);
		}
		else {
			if (GetGlobalNumber("DAN_PATH_STATE") == 3) {
				oSbr = CreateItemOnObject(pc_lghtsbr_003", oPC, 1);
			}
		}
	}
}
if (GetIsObjectValid(oSbr)) {
	DelayCommand(0.1, AssignCommand(oPC, ActionEquipItem(oSbr, 4, 0)));
}
return oSbr;
}

void main() {
object object1 = sub1();
ShowUpgradeScreen(object1);
}

 

So - bypass the intGLOB and stringGLOBs altogether...then I wouldn't need the object sub2() I mentioned before. Because that is my object sub2(), just with a DestroyObject(object1); in the main function.

Whaddaya think?

-QDJ

Link to comment
Share on other sites

Not sure if this matters, but if you're not going to use them, you should remove them - you've left the declarations in but didn't use them, and NWScript doesn't really like that.

 

Also, I don't think you need to declare the subroutine before using it. I never do, anyway.

Link to comment
Share on other sites

// 712: ShowPartySelectionGUI
// Brings up the party selection GUI for the player to
// select the members of the party from
// if exit script is specified, will be executed when
// the GUI is exited
void ShowPartySelectionGUI(string sExitScript = "", int nForceNPC1 = -1, int nForceNPC2 = -1);

 

Hardcoded.

Link to comment
Share on other sites

ok..this works but still, I need to remove my sub2 and just insert my new stringGLOB tags...i cut top off for brevity.

 

intGLOB_151 = 1;
int intGLOB_152 = 2;
int intGLOB_153 = 3;
int intGLOB_154 = 4;
int intGLOB_155 = 5;
int intGLOB_156 = 6;
string stringGLOB_1 = "bastila";
string stringGLOB_2 = "carth";
string stringGLOB_3 = "dan13_WP_council";
string stringGLOB_4 = "g_w_lghtsbr01";
string stringGLOB_5 = "g_w_lghtsbr03";
string stringGLOB_6 = "g_w_lghtsbr04";
string stringGLOB_7 = "dan_wanderhound";
string stringGLOB_8 = "pc_lghtsbr_001";
string stringGLOB_9 = "pc_lghtsbr_002";
string stringGLOB_10 = "pc_lghtsbr_003";

// Prototypes
object sub2();
object sub1();

object sub2() {
object oPC = GetFirstPC();
object object5;	
int nGlobal = GetGlobalNumber("DAN_PATH_STATE");
if ((nGlobal > 0)) {
	if ((nGlobal == intGLOB_148)) {
		object5 = CreateItemOnObject(stringGLOB_8, oPC, 1);
	}
	else {
		if ((nGlobal == intGLOB_149)) {
			object5 = CreateItemOnObject(stringGLOB_10, oPC, 1);
		}
		else {
			if ((nGlobal == intGLOB_150)) {
				object5 = CreateItemOnObject(stringGLOB_9, oPC, 1);
			}
		}
	}
}
if (GetIsObjectValid(object5)) {
	DelayCommand(0.3, AssignCommand(oPC, ActionEquipItem(object5, 4, 0)));
}
return object5;
}

object sub1() {
object oPC = GetFirstPC();
object object3;
object object4 = GetItemPossessedBy(GetFirstPC(), "dan13_plotcrys");
SetPlotFlag(object4, 0);
DestroyObject(object4, 0.0, 0, 0.0);
int nGlobal = GetGlobalNumber("DAN_PATH_STATE");
if ((nGlobal > 0)) {
	if ((nGlobal == intGLOB_148)) {
		object3 = CreateItemOnObject(stringGLOB_4, oPC, 1);
	}
	else {
		if ((nGlobal == intGLOB_149)) {
			object3 = CreateItemOnObject(stringGLOB_6, oPC, 1);
		}
		else {
			if ((nGlobal == intGLOB_150)) {
				object3 = CreateItemOnObject(stringGLOB_5, oPC, 1);
			}
		}
	}
}
if (GetIsObjectValid(object3)) {
	DelayCommand(0.1, AssignCommand(oPC, ActionEquipItem(object3, 4, 0)));
}
return object3;
}

void main() {
object object1 = sub1();
DestroyObject(object1, 0.0, 0, 0.0);  
object object2 = sub2();
ShowUpgradeScreen(object2);  	
}

 

When I originally did it I only had 3 closes at the end of the if/else statements in sub2, so the pc wasn't equipping the saber. So I fixed that but haven't re-tested.

Link to comment
Share on other sites

void main() {
[color="Red"]object object1 = sub1();
DestroyObject(object1, 0.0, 0, 0.0);  
//You may delete the code in red[/color]
object object2 = sub2();
ShowUpgradeScreen(object2);  	
}

 

Seems like it would work. Might as well delete the code I highlighted though. It's garbage now, and it might mess with the new code you put in.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...