Author Topic: Format function?  (Read 886 times)

0 Members and 1 Guest are viewing this topic.

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Format function?
« on: February 06, 2013, 05:57:47 pm »
http://delphibasics.co.uk/RTL.asp?Name=Format

I am certain that this function exists in soldatpascal (since it is used on the text files on soldat's folder), but I don't know the name that is used. Someone help?

:D Thanks!
www.soldatx.com.br - The brazilian Soldat community.

Offline SyavX

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 338
Re: Format function?
« Reply #1 on: February 07, 2013, 03:57:27 am »
I may be wrong, but it seems there's only one format function in Soldat's ScriptCore:
function FormatDate(A: string):String

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Format function?
« Reply #2 on: February 07, 2013, 07:07:20 am »
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Format function?
« Reply #3 on: February 08, 2013, 02:01:12 pm »
Heh, I think you misunderstood. I refer to the Format fuction that formats (lol) strings. Like:

Code: [Select]
writeln(format('My name is: %s',[getplayerstat(id,'name')]);
Like I said, it is used on the soldat text files (like: "You killed %s"). I have a very similar purpose for the use of that function. Shoozza must know this, since he has access to the soldat's core. Maybe I'll send him a message to look at this topic :p
www.soldatx.com.br - The brazilian Soldat community.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Format function?
« Reply #4 on: February 08, 2013, 02:57:22 pm »
There's nothing like that exported to scriptcore. At least not yet.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline Shoozza

  • Retired Soldat Developer
  • Veteran
  • ******
  • Posts: 1632
  • Soldat's Babysitter
    • Website
Re: Format function?
« Reply #5 on: February 09, 2013, 12:28:49 am »
Falcon is the one who works on the ScriptCore so he knows it ;)

I think for you string format example you can use normal string concatenation:
Code: [Select]
writeln('My name is: ' + getplayerstat(id, 'name'));
You can ofc write your own format function which parses the format string.
Rules
Tools: ARSSE - SARS - SRB - chatMod

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Format function?
« Reply #6 on: February 09, 2013, 03:02:46 am »
Falcon is the one who works on the ScriptCore so he knows it ;)

I think for you string format example you can use normal string concatenation:
Code: [Select]
writeln('My name is: ' + getplayerstat(id, 'name'));
You can ofc write your own format function which parses the format string.
Thank you - both of you! - for taking the time to answer here!

I have taken the initiative to build my own format function. It is not the same, though.

Code: [Select]
function format(const text: string; const data: array of variant): string;
var s, q: integer;
begin
result := '';
for s := 1 to length(text) do if copy(text,s,1) = '%' then begin
    q := strtoint(copy(text,s+1,1));
    case vartype(data[q]) of
        3: result := result + inttostr(data[q]);
        256: result := result + data[q];
        end;
    end else if copy(text,s-1,1) <> '%' then result := result + copy(text,s,1);
end;

Example of usage: writeln( Format('One, two, %0, %1, %0!',['three',4])); //Writes: "One, two, three, 4, three!"
You basically type "%" and then the index of the Data array.

Only works with integers and strings, though (I will only use it with those var types).

Thanks for your help! :D
www.soldatx.com.br - The brazilian Soldat community.