And so on… it's alot of functions for use in scripting plugins for GTA IV.
I want to sort the lines into the function name, and how many parameters it has (and possibly the parameters too, even though they are there, this way would be neater IMO).
E.G.
("ADD_SCORE", playerIndex, score)
Would turn into:
Function = ADD_SCORE, Parameters = 2 (playerIndex, score)
(or something like that).
The way i've decided to count the parameters is to count the commas , so like:
#!/usr/bin/perl
use strict; use warnings;
print "File: "; chop(my $file = <STDIN>);
open(FILE, $file); my @lines = <FILE>; close(FILE);
foreach (@lines) { my $count = ($_ =~ tr/,//); chop($_); print SAVE "The function: $_, contains $count parameters.n"; }
close(SAVE);
This returns: "The function: ("ADD_SCORE", playerIndex, score), contains 2 parameters." (for the first line).
I would like it to return: "The function: "ADD_SCORE", contains 2 parameters (playerIndex, score)." (i wouldn't mind if the function was in talking marks or not).
I've tried using the split() function, but that doesnt work too well.
I would use split as well. But perl is not my first language . May u can post the code where u use split: I would use something like that:
foreach (@lines) { my $count = ($_ =~ tr/,//); chop($_);
@parts =split(/ /); //After every space try a new position in array print SAVE "The function: $_, contains $count parameters( $parts[0], $parts[1]).n"; }
With great power comes great responsibility. Have a look at this webpage: securityoverride.com
Post edited 10:34 pm – April 20, 2010 by lost_prophet_
I've tried a few more things, so far i've got it to do this:
The function: ("REGISTER_PLAYER_RESPAWN_COORDS", playerIndex, x, y, z), contains 4 parameters – (playerIndex, x, y, z). The function: ("SET_EVERYONE_IGNORE_PLAYER", playerIndex, value), contains 2 parameters – (playerIndex, value). The function: ("SET_PLAYER_CAN_BE_HASSLED_BY_GANGS", playerIndex, value), contains 2 parameters – (playerIndex, value). The function: ("SET_PLAYER_CAN_DO_DRIVE_BY", playerIndex, value), contains 2 parameters – (playerIndex, value). The function: ("SET_PLAYER_CAN_USE_COVER", playerIndex, value), contains 2 parameters – (playerIndex, value). The function: ("SET_PLAYER_CONTROL", playerIndex, value), contains 2 parameters – (playerIndex, value). The function: ("SET_PLAYER_CONTROL_ADVANCED", playerIndex, unknown1, unknown2, unknown3), contains 4 parameters – (playerIndex, unknown1, unknown2, unknown3).
Which is exactly what i want (for the end of the line at least).
The code I came up with is very sloppy (Thanks to Teddy for the idea), could be changed and probably shortened, but i want to get the script doing what i want before i try to optimize it.
foreach my $function (@lines) { my $count = ($function =~ tr/,//); chop($function); print SAVE "The function: $function, contains $count parameters"; if ($count > 0){ print SAVE " – ("; } my @parts = split(/ /, $function); my $partssize = @parts; foreach(my $i = 1; $i < $partssize; $i++){ if ($i == 1) { print SAVE "$parts[$i]"; } else { print SAVE " $parts[$i]"; } } print SAVE ".n"; }
(that's the only bit I changed).
Right now im working on how to separate the function name from $function using substr(), but substr() doesn't like me very much :p, e.g. –
The function: ("REGISTER_PLAYER_RESPAWN_COORDS", playerIndex, x, y, z), contains 4 parameters – (playerIndex, x, y, z).
I've got it to return this –
The function is: "ADD_SCORE", playerIndex, score).
Using the following code:
foreach my $function (@lines) { my $count = ($function =~ tr/,//); chop($function); my $this1 = ($function =~ /"/g); # this get the first quotation mark, i cant get the last one, i cant figure out how to. my $function2 = substr($function, $this1); #, $this2); print SAVE "The function is: $function2.n"; }
Edit:
This code works pretty much as i intended it to. Still a bit sloppy, but it works. Could anyone maybe try and optimize this/make it smaller?
#!/usr/bin/perl
use strict; use warnings;
print "File: "; chop(my $file = <STDIN>);
open(FILE, $file); my @lines = <FILE>; close(FILE);