Page 1 of 1

How to declare static array in script?

PostPosted: 20 Apr 2015, 16:27
by grayter
Hi, I'm so frustrated wrrr, please help me with this. I need to initialize a static array in one of my scripts.

This is the code I wrote:

const sArray : array [1..3] of integer = (1,2,3); //according to documentation od delphi basics

I found several solutions on stackoverflow but nothing works :/ I really don't know how to do it. This language is driving me crazy!

I tried to replace this static array with string but guess what... I can't use split function implementations because neither of these implementations does not work in kam.

Do you ever implemented it?

Re: How to declare static array in script?

PostPosted: 21 Apr 2015, 00:19
by Lewin
Unfortunately PascalScript doesn't let you initialise constant arrays as far as I know. It's not a full implementation of Pascal like Delphi or Free Pascal so some stuff like this is missing. You could make it a global variable then initialise it in OnMissionStart. I am not aware of a better solution at the moment.

Re: How to declare static array in script?

PostPosted: 21 Apr 2015, 07:03
by grayter
Hmm, okay. Please tell me then how to implement split function. I tried to wrote this function on my own but functions I needed didn't work. Any implementations use functions which kam script don[t recognize i.e. copy or SplitString. Have you public function to split text by separator in code? DelphiBasics and PascalScript implementations (found in stackoverflow) doesnt' work either.

Re: How to declare static array in script?

PostPosted: 21 Apr 2015, 18:34
by Krom
Hmm, okay. Please tell me then how to implement split function. I tried to wrote this function on my own but functions I needed didn't work. Any implementations use functions which kam script don[t recognize i.e. copy or SplitString. Have you public function to split text by separator in code? DelphiBasics and PascalScript implementations (found in stackoverflow) doesnt' work either.
What do you want to achieve with the Split function ? Maybe it's better if you say what you want to get in the first place.

Re: How to declare static array in script?

PostPosted: 21 Apr 2015, 18:55
by grayter
Thanks for your responses.
I'm working on universal script to compare assets and resources of each player with loss to leader in real time. I would like to define in first line in the script which players should be included in those calculations. I know that can be declared in OnMissionStart procedure but I want to do this as simple as possible for regular user. I would like declare something like:

const statPlayers = '1,2,7'; //player 1,2 and 7 should be included in calculations

Then I would like to split this string to array of X elements and compare ids inside my function. I am only asking if there is a function like this, if not I will handle this in another way.

Re: How to declare static array in script?

PostPosted: 21 Apr 2015, 23:15
by RandomLyrics
try this, it will saves active players to array. and regular user dont have to do anything. moreless pseudocode xDD:
  Code:
OnMissionStart() statPlayers[0] for int = 0 to 8 if States.PlayerEnabled(i) then SetLength(statPlayers, Length(statPlayers)+1) statPlayers[i] = i; end; end;

Re: How to declare static array in script?

PostPosted: 22 Apr 2015, 06:49
by grayter
Thanks, I have this piece of code working for me right now :) But I am looking for a script to split string to array by separator.

Re: How to declare static array in script?

PostPosted: 22 Apr 2015, 11:08
by grayter
Nevermind, I wrote this function myself. Thanks for help.

Re: How to declare static array in script?

PostPosted: 22 Apr 2015, 14:19
by RandomLyrics
post it here, your function, for descendants xD