View Full Version : initializing an array, the easy way?
gsquare567
03-14-2007, 02:32 AM
in java, it would look something like this:
String[] someArray = {"IMTHEFIRSTSTRING", "IMTHESECONDSTRING"}; // etc
in scar, it would look like... uhh:
var someArray : array of String;
someArray[0] := 'IMTHEFIRSTSTRING'; // etc
so a) how can i initialize it the easy way, and b) is it possible to initialize it without setting the array size before it is initialized so it is sized automatically?
thanks. btw this is for autotalker. a small opinion on that too: what method is best for typing, sendmytext, humantype, or sendtext... etc. im totally new to this language so anything will help! thanks a lot!
edit:figured out how to initialize an array, someArray := ['s1','s2'];
now another just a small opinion on that too: what method is best for typing, sendmytext, humantype, or sendtext... etc. im totally new to this language so anything will help! thanks a lot! and, more importantly, how do i get the current player's levels?
Boreas
03-14-2007, 04:06 AM
var somearray: array of string;
begin
somearray:=['square','brackets','and','separated','by','commas '];
Also look in SRL/misc/arrayloader.scar
edit: look at SRL/core/autotalk.scar
look at SRL/core/gametab.scar
gsquare567
03-14-2007, 10:34 PM
awesome, thanks. and how might i a) be able to make an array of Integer or String as a constant, and b) be able to get the array's length to use it in a for loop, like so:
for i := 0 to arrayLength do
and the gametab program really helped, thanks for that!
Smartzkid
03-14-2007, 10:50 PM
for i := 0 to getarraylength(array) do
TypeSend(' ') works quite well for sending text
gsquare567
03-14-2007, 11:20 PM
ok, thanks a lot. and what about declaring an array as a const?
Boreas
03-14-2007, 11:24 PM
try
const somearray=['square','brackets','and','separated','by','commas '];
gsquare567
03-15-2007, 12:50 AM
already tried that, didnt work :S came up with another question: how do i split a string like 'hi how are you' into an array of string of ['hi','how','are','you'], so basically splitting up the words with ' ' (a space)
edit: im an idiot... strToStrArray in misc/arrayloader
edit again: how do you compare strings? like in java string1.equals(string2);
edit again again: what is the proper format of if, else if, and else.
Smartzkid
03-15-2007, 01:16 AM
if(true)then
begin
...
end else
begin
...
end;
if(true)then
begin
...
end else
if(true)then
beign
...
end else
......
gsquare567
03-15-2007, 01:42 AM
awesome thanks a lot, now how about my other question: can you compare strings with a simple "="?
Boreas
03-15-2007, 02:25 AM
program New;
var fir,sec:string;
begin
fir:='lol';
sec:='lowl';
if fir=sec then writeln('yea1');
fir:='lol';
sec:='lol';
if fir
gsquare567
03-15-2007, 02:28 AM
sorry, i'll try to test out before i ask questions from now on :D thanks for your incredible help boreas, rep++!
Boreas
03-15-2007, 02:46 AM
Np. Oops I didn't copy the whole thing, but I think you got the idea.
program New;
var fir,sec:string;
begin
fir:='lol';
sec:='lowl';
if fir=sec then writeln('yea1');
fir:='lol';
sec:='lol';
if fir=sec then writeln('yea2');
end.
gsquare567
03-15-2007, 02:52 AM
now a big question:
i always get 'type mismatch' errors in ifs if i use more than one comparison type like (string = string and boolean). here is an example:
if((InvCount < 27) or (InvCount = 27 and (FindItemColor(arrowheadinvcol))) then
as you can see i tried covering them with brackets but still nogood
edit: i feel so stupid, i post here then i try it for the 50th time and it works... wrong brackets...
if(InvCount < 27) or ((InvCount = 27) and (FindItemColor(arrowheadinvcol))) then
another problem lol:
how can i make an array inside the const block like
const
itemcolor = [3412431,132412];
Boreas
03-15-2007, 02:57 AM
if(
(InvCount < 27)
or
(
(InvCount = 27)
and
(FindItemColor(arrowheadinvcol))
)
) then
gsquare567
03-15-2007, 03:05 AM
i guess i beat u to it this time, but urs is neater ;) now how do i make an array constant?
Boreas
03-15-2007, 03:42 AM
if
const
itemcolor = [3412431,132412];
doesn't work then I'm stumped. Just make it a var and have proc near the top (how bout stick it in declareplayers) set the var.
gsquare567
03-15-2007, 03:44 AM
yay stumped you! ok, i'll do that thanks.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.