#Intro to Scripting: Getting started/Making a button
1 messages ยท Page 1 of 1 (latest)
yeap, already did it
did that too
This will give you a copy of the world you can edit, and save you all the headache of building.
ohh, this was a full tutorial for others, get it now
ok, so in your new world. Add in though the resource/prefab browser the Campaign game mode.
Then we will have a functional world to spawn into, and test our button we will build in second.
Add in a prefab (prebuilt/configed item) it can be anything. I'm using CargoContainer_01_20ft.
ok, i got a wooden crate
Ok so when you drag it into the world, now you got a game object (entity) that comes with at least a mesh and rigid body (body, and collision) so you can see it ๐
Does it have a action manager?
The picture are the "components" or addons to the object, that give it properties/abilities - the whole system is designed around injected abilities/properties to control and grant actions.
It does not have it, do I add it?
Yep, add it in. It shouldn't have one by default - its just a box ๐
Ok the stuff in the bottom of the object boxes are all the variables, and the very slick thing - is that they are in the code, as a single line, and then workbench (the editor) turns them into this gui.
You can see this by right clicking on the comp and clicking jump to script def.
The stuff with the [ ] are the attributes that create the stuff you get to edit though the editor. You can, edit these though code/scripts, or you can edit them, like we are doing now - though the editor.
Editor makes complex things less complex, but its your call.
For now we will use the editor, but its good to understand how to look up code, and whats going on.
Ha. Ok, so I just looked - and there is no [ ] for this class ๐
there is but it doesn't have anything
Yep. Let me find a example before we move on ๐
[Attribute blah blah blah] that sets up the gui and tells it how to display things.
Important when you build your own code.
Ok, back to the box. To give it an action. We first click the + sign (which in the backround is adding to an array) in action context
Gimmi one sec to switch to a box.
Yea, I was trying to edit something that had a default action that I couldn't remove ๐
Things with Dots on the side, take classes or config files as far as I know. In this case we will click "set class" which will build a class of type unknown to us, or it will let us select a type - if its setup for it in the background.
In this case it is, and we will do UIInfo.
Name is the words. Description is the words I think are seen in inventory menu.
Under Position, we will feed it a pointinfo - which will let us set where the invsible center is of the soon to appear "Action button"
UI info is like what you see when you open a door - no "button" but a "word" that triggers an action (so a button) ๐
Play with the Y offset so it is above the box, or near the top. The ground looks weird.
Yea prefect. So if you want it directional - click off Omnidirectional (good for signs and frontfacing things)
Now in addtional actions, is where we put the hook. I don't know exaclty which one triggers code but most people I think use SCR_ScriptedUserAction.
We can leave it blank and try the world now, and you'll see your action.
so, the action does not appear
Yep, one seconf. I'm missing something.
Weird. I just tried what I had eariler and nadda. Give me a few more seconds ๐
dont worry
Well try this and maybe it will work on your end.
That creates the action, and It overwrites the text in a few cases like with toliet flushing.
But base action should work.
ah shit.
You gotta link the parent context list ๐
I knew I was missing something ๐
Its the first line under scripted user action or any of them as far as I know See "parent blah blah"
click +
The drop down will give you a selection of the action contexts
it is tiny as f...
cause you have the omnidirectional
oh
ah ok.
Let me see what it does.
Makes the text perhaps slighlty smaller, but no micro text.
Just to double check, you dragged this box into the gameworld - not double clicked it in the editor world.
yes, I dragged it
yeap
And its still small?
I wonder if it has anything to do with not having textures on your flags as well
something's different?
You have the timer up, and the numbers look like eden or error.
Oh poop, we also need the faction manager
No sides.
ok, dragged it
See if that resolves your problems.
Did you give the UI info any text in yours?
Take a screen cap of the "additional actions "area again. the last photo didn't have the UI setup
scroll down into the addional area
Na see "UI "SET CLASS" ๐
Theres our problem ๐
That attaches the second "gui" to appear based on settings from the class we chose.
In most cases, text that you type into the UI info area there.
it doesn't seem that small anymore
eh?
gotta admit, I've got lost here
So that is kinda the process. World object, gets comps (components) and then we modify them to change the outcome.
As a scripter, you can create classes, change variables used and change how things interact in the background.
Le peite poo poo = Little shit in french
oh ok
poo poo not real french.
Anyways, so that kinda gives you a overview of the process. So what you can do, to learn, is drag in some other stuff like ammo boxes, and cars and stuff - and see what "components" are attached to them, and even look at the scripts in the code.
A thing is just a mesh and a rigid body - everything else, is what lets it do things.
In this case, we attached a useless button to a box ๐
If we take away the comp, it becomes a useless box again
if we delete ridgid body, we can walk though the box.
and if we delete mesh, the box is invisible.
knew that atleast
So say you wanted to make that box a supply depot - you could bring in the supply comps to make the box have the behaviors of the supply sign you see ingame.
But thats as far as I managed to get, because there is some backround stuff needed to get the supply system working, I haven't quite figured out.
Hey, I'm just popping in to say that if you want to know how to manipulate supplies via script, look up the script class SCR_SupplyBasesContextAction for a bunch of hints. I don't know if it's the exact behaviour you want, and to be honest I don't have time to answer all your questions, but it will get you started.
If you drag in "Sign Supply" you can see the differences from you box, and that's a working supply node
Disregard that, not the right one
thank you
maybe "SupplyCache_S_FIA_03"?
it has the sign xd
SCR_ResourceComponent is what gives you the "Supply" system
You can stick it on anything, and with the action manager - you trigger the opening of the inventory to see it.
Anyways, that should give you stuff to look at. By dragging in things, you can see how they are "put together"
This "part in editor" "part in code" will get confusing later on. As you'll find a lot of "empty code" because its all handled in the editor, or vice versa. Empty object properties, because its all spawned and done in code.
In code, you can hold control and click on the class parent to go up a level and see what the parent brings to the table. All the children have the parents stuff.
So if you see a comp that is almost empty, its probably bring stuff down from a few layers up.
like OOP, right?
Yep. This is "C/C++ ish"
good to know
Also good to know is "ref" is strong reference / a pointer, I think everything is basically a weak pass by reference anyways, and everything is managed by a garbage collector, at the highest level (the devs coded it in)
So when your passing refs which you will do a lot, because it saves memory and its fast, you need to null the refs or they will lag out the system eventually. But you can read all this on the wiki.
Anyways, feeling a little more closer to understanding this mess?
There is no init main, its just objects coming to life and events like touching them and them spawning on game time.
In the backround there is a huge loop that checks on and updates everyone, which you don't want to hold up - or you'll crash the FPS of the game.
ok
Replication is server code to update clients (players) but ignore that for now ๐
look, one thing I dont get is how the action manager of the sign opens a inventory
like, its "#AR" some kind of special variable or something?
# is code for "Look this up in the string table" this is for localization so everyone gets ARMA in thier own lanuage (we are supposed to do this as well for mods)
oh, ok
So whats going on is when you choose a "class" to be your addtional actions your choosing a script to be read. In this case, this one.
If we find that script, we will see a trigger that opens the inventory
That jump to is so useful. ๐
And presto. simple easy clean script
``#ifdef and ifndef` are codes to knock out blocks of codes based on variables at compile time being true or not. Used for performance to remove chunks of code, rather have it sit there and run over it.
Not really needed for us commoners, unless we get fancy
so the #ifdef and ifndef takes this code off the loop until something happens?
If n def is "if not defined" then this block of code.
So if not defined (if DISABLE INV is 0, null or less then 1 - I think) do run this block of code.
ifdef would run the code contained/put in the script on 1 or greater
Its ways of cutting and pasting in/out blocks of code. It isn't like a if statement that gets run at code time. This gets run at "Code building time" when its reading the text, before it reads it as code.
ok... and what if I want it to run a script that I made?
So you would, I assume, Create a script file with TAG_XXXXX - Tag being your codeword to use to make sure your files don't conflict with other mods.
class TAG_SAMEASTHEFILENAME : SCR_InventoryAction
{
/// Your stuff here
}
What you choose after the : will set the tone for the action, I haven't worked with actions a bunch, but if you go up the chain (child->parent->parent->parent) you'll find they must have the code for "being a action"
What you call the class isn't super important, but good practice is the same as the filename.
oh shit, didn't even know about that ๐
I just copy and paste from things that work and modify them.
we are both learning at least
So I know "they should work"
I think the common : used for actions is "ScriptAction" but you will have to look at the parents and see what they bring to the table.
Like I was using "Entity" and I learned that "component" has a pile of helper functions and they did all the hard work of extracting data for use. Where as Entity was too high level, and thus isolated.
So using the text search, is a good way to find "how did they do this" and if they already have a class for it.
Oh and casting you can think of it as "taking this thing, and shoving it into the shell of another thing" that then opens up new functions and variables.
It is used a ton to take a more generic thing, and move it into a child of itself.
casting?
Basically but Reforgers casting is not equal to C++ casting. Very simlar though.
I think a dev mentioned its like "pure virtuals" - he was talking about this, or about refs. I can't renember.
But the key point, is casting is not destructive nor does it make a copy.
I meant that I didnt know what casting is, but I think now I have an idea of what it is
oh
Casting is when you take a parent (Moving Object Class) and you cast it into something else (Truck class)
All Trucks are moving objects, and are children of the moving object class - so when you cast a MovingObject into a truck class. The moving object, object ๐ - now becomes a truck, and it "transfers" all of its values over into the same slots that it took from its parent. - but now has all the new values/attributes and function of the child.
You can go the other way and stuff will be hidden.
But the take away is that it's just changing how you look and interact with it, nothing is being moved/copied or destroyed, regardless of direction - so thats useful to know.
I don't think that was the case in C++ but I could be wrong.
so it inherit the variables values?
Yea, more accurately it keeps them when you go from parent to child. Child to parent, you will only be able to "See"/access what the parent had, not what the child has added.
You get class inhertiance right?
I think I do
the child get the params of the parent but no viceversa
Its a easy concept, I wont go over it, but casting, is kinda like forcing it or switching between things. You need it to take complex thing, and make it less complex, or vice versa - because OOP is a pain sometimes and your code needs to be as generic as possible.
and any changes made to the child do not modify the parent, but it does the other way around
kinda, once "spawned"/instanced, then its set.
Unless some fancy keywords I can't renember off hand, I think can override that - but lets presume, code cant change at runtime.
So if a class says "int XYX, String XYX, float XYX" and the child says "int poopy"
the parent has the first 3, and the child has the first 3, from the parent, and poopy.
This lets you have things like "Base class to open a door, child class to open red doors, child class to open red explosive doors"
As you go down, you can add detail, then you can call, cast or use - what level of detail is needed. Because not every door, will be red, or explosive.
As a modder, we go in an find the "red door area" and add a "blue door area"
We reuse the door class with all the code to make doors work, and we add in, the stuff needed for a blue door we want.
Ok
Anyways. I think you kinda get it. Enough to explore and learn ๐
yea, I have to lookup the C tutorials from microsoft
Somewhat yes, or at least read the BI wiki on keywords in scripting
at least to learn some things
that too
90% of the scripts are going to be calling functions from the parent or other classes. Your not able to write game engine calls. Only using what is availabe to you.
So even with scripting, you don't need strong programming skills. Just copy and paste and logic.
But you'll get it.
I just have kinda of a idea to test all this "walkthru" you gave me
try to make a button inside (or outside) of a car that makes it blow up
should be "easy"
Thats not to hard. Damage Manager Comp is what you need to talk to. Start there, and look at hitzones and the comps that come with a vehicle
gotta find what holds the vehicle hp and set it to something like "-1"
Vehicles are somewhat complex.
Yep. thats basically the correct logic.
I think you set it to near zero, because below zero might cause issues. Cars burn and such.
But anyways good luck for now ๐
yes, but what triggers the explosion is the armor getting to 0
Thank you for your time
The HP system is complex now and pritty cool. The HP is now a sum of the hitzones, and if a hitzone gets to 0 is can or can not blow the whole thing. When the total HP drops, then things happen.
Its much smarter now, so we can have broken tanks and birds an such.
Anyways you'll see
ok good to know then
Have fun
thank you, again
Hehehe. Help is thanks in what language?
I was distracted
Ah then disregard ๐
idk why I writed help
Np. I was looking forward to learning something cool ๐
๐
Intro to Scripting: Getting started/Making a button
no need to go that deep, c#/python/php is enough to understand enough about enfscript, i mainly do php and could do a koth gamemode and other random mods
basic oop and script knowledge is enough imo
thing is I got the logic of programming, but 0 sintax knowledge of C
nice, logic (and will) is all that matters imo
kinda depend on your field, you can get by with adapting copy pasta
I should be able to do things then