SRL Archive - OSR Help

Sup with this?


Sin

2012-12-02 02:21:30

type
Ore = record
Col,Tol:Integer;
Name:String;
HMod,SMod:Extended;
end;
 
var
Ores:array of Ore;


with Ores[0] do
begin
Col := 2568527;
Tol := 11;
HMod := 0.05;
SMod := 0.62;
Name := 'Iron';
end;

SRL Compiled in 0 msec
Paired with SMART[4592]
Error: Out Of Range at line 48
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap, SRL - NavBar Bitmap]



I'm clueless at what's going on :s

KingKong

2012-12-02 02:32:30

you need to use setlength or use ores := [toOre(…)]

YoHoJo

2012-12-02 02:34:13

Bro you know better.
Post the entire script or at least tell us what line 48 is if you want to be a secretive noob.

My guess is maybe just maybe you need to set the length first? I'm not too great with types.

Chris

2012-12-02 02:34:22

array [0..10] of ore;

That's my guess

Sin

2012-12-02 02:35:55

From: KingKong
you need to use setlength or use ores := [toOre(…)]


From: YoHoJo
Bro you know better.
Post the entire script or at least tell us what line 48 is if you want to be a secretive noob.

My guess is maybe just maybe you need to set the length first? I'm not too great with types.


SetLength worked, thanks!

YoHoJo

2012-12-02 02:36:48

Man SRL rocks! This community is great.

masterBB

2012-12-02 05:53:19

It is very important to understand the principle why you have to set the length of an array. It will teach you a bit about memory and how to use it. This is important because in Lape there isn't any check for array length and you will just get a value random from you memory, or even worse you set the value of a random piece of your memory.

Image your memory as a cupboard without drawers. When you create a variable you will create a drawer with the exact size of what you want to put in the drawer and if there is still space in the cupboard you will place it there. The variable you use in your script is a reference to that drawer. For a integer this drawer is exactly 32 bits big. Or a Byte which is 8 bits. And a Boolean which is 1 bit.

When you create your own type you will go full hardcore engineer mode. You will design your own custom drawer. You will only create the building plans of the drawer, not the drawer itself. So if you want to use it you will still have to create it.



[INDENT]type Dog = record //Creating the building plan
[INDENT]size, smell, gender: Integer;[/INDENT]
end;

var a: Dog; //Creating the drawer and placing it in the cupboard

a.size := 5; //Putting stuff in the drawer
a.smell := 99999;
a.gender := -1;[/INDENT]

An array is harder, how big is that drawer? Well that depends of course, how much you want to put into it. So a few tricks were created. Now I will only discuss one. You start with creating an array drawer. This drawer basically contains; "The following x drawers have the size of typeX".

[INDENT]var b: Array of Dog;[/INDENT]

Note that there still isn't any drawer to store your dogs in. That variable doesn't contain any dogs. So to make use of it we have to create dog drawers like we did before. Let's say we got four dogs.

[INDENT]setLength(b, 4); // Creating four dog drawers

b[0].size = 3; //Putting stuff in the drawers
b[0].smell := 9999;

etc…[/INDENT]

Now when you call b[0] you will look into drawer b, which tells where to find the correct drawer. If you didn't set the Length it will give an error in pascalscript, in Lape it will give you a random drawer out of your memory, that can contain anything. This is dangerous if you put random stuff in it, simba could crash.

Sin

2012-12-02 05:59:42

From: masterBB
It is very important to understand the principle why you have to set the length of an array. It will teach you a bit about memory and how to use it. This is important because in Lape there isn't any check for array length and you will just get a value random from you memory, or even worse you set the value of a random piece of your memory.

Image your memory as a cupboard without drawers. When you create a variable you will create a drawer with the exact size of what you want to put in the drawer and if there is still space in the cupboard you will place it there. The variable you use in your script is a reference to that drawer. For a integer this drawer is exactly 32 bits big. Or a Byte which is 8 bits. And a Boolean which is 1 bit.

When you create your own type you will go full hardcore engineer mode. You will design your own custom drawer. You will only create the building plans of the drawer, not the drawer itself. So if you want to use it you will still have to create it.



[INDENT]type Dog = record //Creating the building plan
[INDENT]size, smell, gender: Integer;[/INDENT]
end;

var a: Dog; //Creating the drawer and placing it in the cupboard

a.size := 5; //Putting stuff in the drawer
a.smell := 99999;
a.gender := -1;[/INDENT]

An array is harder, how big is that drawer? Well that depends of course, how much you want to put into it. So a few tricks were created. Now I will only discuss one. You start with creating an array drawer. This drawer basically contains; "The following x drawers have the size of typeX".

[INDENT]var b: Array of Dog;[/INDENT]

Note that there still isn't any drawer to store your dogs in. That variable doesn't contain any dogs. So to make use of it we have to create dog drawers like we did before. Let's say we got four dogs.

[INDENT]setLength(b, 4); // Creating four dog drawers

b[0].size = 3; //Putting stuff in the drawers
b[0].smell := 9999;

etc…[/INDENT]

Now when you call b[0] you will look into drawer b, which tells where to find the correct drawer. If you didn't set the Length it will give an error in pascalscript, in Lape it will give you a random drawer out of your memory, that can contain anything. This is dangerous if you put random stuff in it, simba could crash.


Thanks! I was getting an error when I was calling an array inside an array, and this sorta cleared it up :)

Rezozo

2012-12-02 09:00:27

From: YoHoJo
Man SRL rocks! This community is great.


I feel an unintended pun ;)
Rocks…Ores…
~Rez

Kasi

2012-12-02 09:50:30

From: Rezozo
I feel an unintended pun ;)
Rocks…Ores…
~Rez


I feel an SRL Member should have known better -.-
FML seriously tho? out of range error? how many other ways can you get that?

superuser

2012-12-02 12:27:12

From: Kasi
I feel an SRL Member should have known better -.-
FML seriously tho? out of range error? how many other ways can you get that?


My thoughts exactly. These are basic stuff…

Sin

2012-12-02 12:35:43

From: Kasi
I feel an SRL Member should have known better -.-
FML seriously tho? out of range error? how many other ways can you get that?


4 AM in the morning mate, when I just woke up with nothing better to do.

YoHoJo

2012-12-02 12:37:00

Why ya'll being so mean?! Everyone has brain farts sometimes!

Kyle Undefined

2012-12-02 12:39:01

I never have brain farts, because I am awesome.

superuser

2012-12-02 12:40:15

I usually have arsefarts, in public places..

E:

I'm traumatized.

Ashaman88

2012-12-02 12:57:30

No need to hate, why not try to help instead?

Awesome explanation masterbb!

superuser

2012-12-02 12:58:44

From: Ashaman88
No need to hate, why not try to help instead?

Awesome explanation masterbb!


No hate here, only pondering..

Rezozo

2012-12-02 13:01:40

The pondering hurts :( JK
~Rez

masterBB

2012-12-02 14:43:57

Don't feel superior above other just because there is one basic thing you knew he didn't. That doesn't equal you know more then the other. Learning is a process of gathering information and understanding it. This is usually randomly grabbing pieces which you require on your task. It happens often that you miss one thing that most of the others didn't miss.

Kasi

2012-12-02 14:47:31

From: Kyle Undefined
I never have brain farts, because I am awesome.


just narcissistic

footballjds

2012-12-02 15:03:22

From: Kyle Undefined
I never have brain farts, because I am awesome.


true story.
@s1n, come on bro, out of range…

YoHoJo

2012-12-02 15:18:26

Spamfest.
Closed.