HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Some questions about structs

09-03-2008, 11:36 AM#1
the-thingy
1) Is it possible to do something like local MyStruct data = SomeInt? (yes, I know structs are integers, but I've never actually set it to a specific integer before )

2) If the second one of the above is possible, is there anything specific that needs to be done before I can do it, or can I directly set the struct variable to SomeInt? I'm making a lightning system and I want some fairly easy way to allow users to change some of the lightning's properties (such as the source, the target, the RGB values) after the lightning has been created
09-03-2008, 11:55 AM#2
Blubb-Tec
to 1): yes, that is possible.

to 2): depends. normal structs only use integers values that are are >0 and <8190(or 8191, not 100% sure), due to the fact that they're actually used as indexes for global arrays that store the variables of each struct instance.

However, if you look at vex' ARGB, you will see that you can do all kinds of fancy stuff with them, aslong as you know what you're doing. Try to figure out how ARGB works, that will help you alot.

now the question is, WHY you do not want to use methods or custom operators to let the user change you lightning's properties?
09-03-2008, 12:11 PM#3
the-thingy
1) Fair enough
2) Thanks for the tip on ARGB

Quote:
WHY you do not want to use methods or custom operators to let the user change you lightning's properties?
If I used methods, I would have to allow direct access to the struct, wouldn't I? If so, there will either be (1) someone who thinks the struct should remain private or (2) someone who feels the need to break sh*t and then claim that the system fails because they decided to do something retarded... so, if I use a function, that can act as a middle-man, of sorts, so people can manipulate stuff without having direct access

Anyway, until I find something wrong with how I'm doing things so far, it's going to stay that way
09-03-2008, 03:58 PM#4
Alevice
You always has to expose the way the user can intereact with the struct behaviour. You just need to tell then what functions are available to them, by setting the public and documenting them. The innards (to be precisoe, how your struct does what it was meant to do) should be kept private, though.
09-03-2008, 05:01 PM#5
the-thingy
Meh, I've got everything coded now (and I don't plan on changing it) - having normal functions acting as a go-between for end-user and struct works just fine

Anyway, if I allowed access to the struct, someone will, inevitably, be stupid enough to call DestroyLightning (data.tl) and come complaining to me when the game crashes as a result of their stupidity >.>
09-03-2008, 06:36 PM#6
Alevice
well, you can't be 100% foolproof. if they are stupid to do that, they shouldn't be using your scripts to begin with.
09-03-2008, 07:24 PM#7
the-thingy
Well, if they start messing with the system code itself, they get what they deserve