Jump to content

Wondering about some code in P5Tweaks.tp2


Bursk

Recommended Posts

For those of you not familiar with the mod, here's the link:

 

http://www.shsforums.net/index.php?showtopic=24586

 

pro5 doesn't seem to be around which is why I'm asking here. What we're wondering about is on line 67 of the .tp2:

 

APPEND ~P5#PATCH.2DA~ ~ %override%~

 

You'll notice that there's a space between ~ and %override%~

 

Does this affect the installation/operation of the mod? I've managed to install the mod both with and without the space there, but can't tell whether it's working correctly. I mean, I get the message that the mod has been successfully installed, but surely the space must make some difference, no? And since this is the only time a space appears between ~ %override%~ I'm wondering if it's a mistake.

Link to comment

It's probably a mistake, but I don't think it makes a difference. %override% is a variable in this case, not the override folder (unless that's what the variable stands for). I have no real idea what he was trying to do outside of that one line of code though.

Link to comment

It's not a mistake. ~ %override%~ is not the directory where the file is copied, but what is appended to P5#patch.2da.

 

Still, pro5 is an idiot because he uses COPY +.

 

EDIT: apart from the COPY + thing, do not code like he does if you need to 'mark' certain files. Use arrays and PHP_EACH instead (bugger SConrad for the tutorial if you need one).

Link to comment
PHP_EACH

 

Sell me on this, please.

 

Why do I want to use it instead of

COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
 PATCH_IF SOURCE_SIZE > 0x2d3 THEN BEGIN
READ_ASCII 0x0248 os
PATCH_IF ~%os%~ STRING_COMPARE_CASE ~boo~ THEN BEGIN
  PATCH_IF FILE_EXISTS_IN_GAME ~%os%.bcs~ THEN BEGIN
	PATCH_IF NOT VARIABLE_IS_SET EVALUATE_BUFFER ~osa_%os%~ THEN BEGIN
	  INNER_ACTION BEGIN
		EXTEND_TOP ~%os%.bcs~ ~override/p5#dieco.bcs~
	  END
	  SPRINT EVALUATE_BUFFER ~osa_%os%~ ~%os%~
	END
  END ELSE BEGIN
	WRITE_ASCII 0x0248 ~p5#dieco~ #8
  END
END
 END
BUT_ONLY

 

Arrays don't persist if someone wants to install a component, quit, and install something else later, do they?

Link to comment
PHP_EACH

 

Sell me on this, please.

 

Why do I want to use it instead of

COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
 PATCH_IF SOURCE_SIZE > 0x2d3 THEN BEGIN
READ_ASCII 0x0248 os
PATCH_IF ~%os%~ STRING_COMPARE_CASE ~boo~ THEN BEGIN
  PATCH_IF FILE_EXISTS_IN_GAME ~%os%.bcs~ THEN BEGIN
	PATCH_IF NOT VARIABLE_IS_SET EVALUATE_BUFFER ~osa_%os%~ THEN BEGIN
	  INNER_ACTION BEGIN
		EXTEND_TOP ~%os%.bcs~ ~override/p5#dieco.bcs~
	  END
	  SPRINT EVALUATE_BUFFER ~osa_%os%~ ~%os%~
	END
  END ELSE BEGIN
	WRITE_ASCII 0x0248 ~p5#dieco~ #8
  END
END
 END
BUT_ONLY

 

Arrays don't persist if someone wants to install a component, quit, and install something else later, do they?

No, they aren't persistant. However, in pro5's case, he was clearing the 2da file every new component (via the aforementioned COPY +). In your case, arrays are a nobler form of variable variables:

SPRINT $ osa (EVALUATE_BUFFER ~%os%~) ~%os%~

(which will become SPRINT $ osa (~%os%~) ~%os%~ once I remember to fix that).

Also, they allow you to iterate through all the elements of an array, rather than having to leave a 'marker' in a 2da file.

Link to comment

Nah, I know how to use this one (GET_OFFSET_ARRAY, not so much :help: ). I was just curious if I'd been missing something neat.

COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
 PATCH_IF SOURCE_SIZE > 0x2d3 THEN BEGIN
READ_ASCII 0x0248 os
PATCH_IF ~%os%~ STRING_COMPARE_CASE ~boo~ THEN BEGIN
  PATCH_IF FILE_EXISTS_IN_GAME ~%os%.bcs~ THEN BEGIN
	PATCH_IF NOT VARIABLE_IS_SET EVALUATE_BUFFER ~osa_%os%~ THEN BEGIN
	  SPRINT $osa(EVALUATE_BUFFER ~%os%~) ~%os%~
	END
  END ELSE BEGIN
	WRITE_ASCII 0x0248 ~p5#dieco~ #8
  END
END
 END
BUT_ONLY
ACTION_PHP_EACH osa AS index => string BEGIN
 EXTEND_TOP ~%string%.bcs~ ~override/p5#dieco.bcs~
END

 

Thanks for answering though :)

Link to comment

Yes, because $foo(~%bar%~) is a synonim of ~foo_%bar%~. However, fundamentals of Object Oriented Programming teach you that accessing an object's data directly leads to trouble when the object's operations change, whereas using the exported APIs should provide forward-compatibility :help:

Link to comment

...i'm drowning, but you folks don't have the time to teach me several layers of undergrad programming, so i will go sit in the corner and read the weidu docs and try to figure out what the big heavy level 12 archmages of code are casting and hopefully i won't end up like mickey mouse in fantasia caught in a poorly designed array which initiates a cascade error and lands me in an infinite loop with water pouring out of the cd drive...

Link to comment

Depends. It's possible that the "stupid" code is clever, works by miracle, or cause problems.

 

Since the mod is in V1, it doesn't have a forum, and it's the only work by pro5, I wouldn't be inclined to rule out #3 and assume this is clever and/or lucky code.

 

But then again, it is widely known that I am paranoid when it comes to idiots in general, so it's possible that the mod works correctly.

 

To clarify: COPY + means "copy, but do not create a backup of the file". Thus, if the author isn't extra careful (something which I doubt of everyone, save people like Dawg or me), the mod will not uninstall correctly.

Link to comment

Archived

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

×
×
  • Create New...