Author Topic: How can I process the number of players and style from nplayer.ini?  (Read 118 times)

Favdeacon

  • Full Member
  • ***
  • Posts: 42
    • View Profile
Hi,

nplayers.ini lists the number of players and style of multiplay (simultaneous or alternating) in the format "2P sim", "3P alt", or even "4P alt / 2P sim". Building a romlist with nplayers.ini in import_extras passes them on in this format.

I want to extract the number(s) of players and the style(s) from Info.Players for further processing or display as [!somefunction].

My first try was to simply splice off the first character of Info.Players (see below), but it's a dirty hack that doesn't cover two-digit numbers (Royal Ascot II has 12) nor styles or dual styles.

Code: [Select]
function playersStripped()
 {
        local pstrip = fe.game_info(Info.Players).slice(0,1);
        return pstrip;
 }

After doing some reading in http://www.squirrel-lang.org/doc/squirrel3.html I think about a combination of splice() and find(). But I'm a absolute beginner at Squirrel and need some (aka much) help with this. Ideally, the final result may help others in parsing the nplayers.ini.

Cheers
Favdeacon

Favdeacon

  • Full Member
  • ***
  • Posts: 42
    • View Profile
Re: How can I process the number of players and style from nplayer.ini?
« Reply #1 on: June 18, 2017, 04:13:38 AM »
Update: Two friends who know their RegEx helped me write this function:

Code: [Select]
function plnum()
 {
  local ex = regexp(@"(\d+)P(?: (alt|sim))?");
local plinfo = fe.game_info(Info.Players);
  local plex = ex.capture(plinfo);
local plnum = plinfo.slice(plex[1].begin,plex[1].end);
local mpmode = plinfo.slice(plex[2].begin,plex[2].end);
return plnum;
 }

Given fe.game_info(Info.Players) in the format "2P alt" etc. it returns the number of players with one or more digits. As a bonus, the multiplayer mode "alt" or "sim" will be stored in the variable mpmode.

Because I am very new at Squirrel and coding overall, it may be not very optimized. Feel free to tinker with it.

edit: sorry for cross-posting, I realized only after I wrote this that it also was fitting for my own thread here.  :-[
« Last Edit: June 18, 2017, 04:18:25 AM by Favdeacon »

Favdeacon

  • Full Member
  • ***
  • Posts: 42
    • View Profile
Re: How can I process the number of players and style from nplayer.ini?
« Reply #2 on: June 18, 2017, 04:53:16 AM »
This will split lines like "4P alt / 2P sim" (e.g. '88 Games) into an array that will hold the separate parts in index 0 and 1.

Code: [Select]
local plparts = split(fe.game_info(Info.Players), "/");
The next step would be to combine this with the above function plnum() and display the player number that corresponds to the currently selected filter (one for "alt" multiplayer games and one for "sim"). The current filter can be accessed like this:

Code: [Select]
function fname()
 {
    local current_filter = fe.filters[fe.list.filter_index];
local fname = current_filter.name;
return fname;
 }

Alas, all my attempts to do this with if…then or foreach statements have failed so far. Help would be very appriated.

bjose2345

  • Sr. Member
  • ****
  • Posts: 104
    • View Profile
Re: How can I process the number of players and style from nplayer.ini?
« Reply #3 on: June 18, 2017, 05:27:36 AM »
You want something like this ¿?

local image = fe.add_image("[!plnum]", 50, 50, 100, 100)
function plnum( index_offset ) {
   local ex = regexp(@"(\d+)P(?: (alt|sim))?");
   local plinfo= fe.game_info( Info.Players, index_offset ).tolower()
   if ( plinfo.len() >= 1 ) {
      local plex = ex.capture(plinfo);
      local plnum = plinfo.slice(plex[1].begin,plex[1].end);
      return plnum  + ".png"
   } else {
      return "players-unknown.png"
   }
}

Favdeacon

  • Full Member
  • ***
  • Posts: 42
    • View Profile
Re: How can I process the number of players and style from nplayer.ini?
« Reply #4 on: June 18, 2017, 06:14:55 AM »
Thanks for the reply. I don't know if I understand your code correctly. Why did you add the index_offset and tolower to fe.game_info?

My goal is to process "dual" player numbers (e.g. "4P alt / 2P sim") in a way that I can have two different filters for alt and sim games and AM displays the corresponding number of players (e.g. 4 for alt and 2 for sim). Whether the number is shown by text or an image is secondary. I, for my part, want to modify the Game Station Theme which displays the players in text.

In terms of coding, I think about something like this:

  • Split a "dual" number strings into two normal ones.
  • Extract the players number and mpmode from both.
  • Display the players number whose mpmode corresponds with the filter name ("alt" or "sim").