Map Database  •  FAQ  •  RSS  •  Login

How to declare static array in script?

<<

grayter

Barbarian

Posts: 107

Joined: 18 Aug 2014, 12:06

KaM Skill Level: Skilled

Location: Poland

Post 20 Apr 2015, 16:27

How to declare static array in script?

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?
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 21 Apr 2015, 00:19

Re: How to declare static array in script?

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.
<<

grayter

Barbarian

Posts: 107

Joined: 18 Aug 2014, 12:06

KaM Skill Level: Skilled

Location: Poland

Post 21 Apr 2015, 07:03

Re: How to declare static array in script?

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.
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 21 Apr 2015, 18:34

Re: How to declare static array in script?

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.
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

grayter

Barbarian

Posts: 107

Joined: 18 Aug 2014, 12:06

KaM Skill Level: Skilled

Location: Poland

Post 21 Apr 2015, 18:55

Re: How to declare static array in script?

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.
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 21 Apr 2015, 23:15

Re: How to declare static array in script?

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;
<<

grayter

Barbarian

Posts: 107

Joined: 18 Aug 2014, 12:06

KaM Skill Level: Skilled

Location: Poland

Post 22 Apr 2015, 06:49

Re: How to declare static array in script?

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.
<<

grayter

Barbarian

Posts: 107

Joined: 18 Aug 2014, 12:06

KaM Skill Level: Skilled

Location: Poland

Post 22 Apr 2015, 11:08

Re: How to declare static array in script?

Nevermind, I wrote this function myself. Thanks for help.
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 22 Apr 2015, 14:19

Re: How to declare static array in script?

post it here, your function, for descendants xD

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 8 guests