#Intro to Scripting: Getting started/Making a button

1 messages ยท Page 1 of 1 (latest)

deep ingot
#

So come on down.

#

Worlds/Arland/Arland - will be even easier.

ancient vine
#

yeap, already did it

deep ingot
#

File -> New World -> Sub-Scene

ancient vine
#

did that too

deep ingot
#

This will give you a copy of the world you can edit, and save you all the headache of building.

ancient vine
#

ohh, this was a full tutorial for others, get it now

deep ingot
#

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.

ancient vine
#

ok, i got a wooden crate

deep ingot
#

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.

ancient vine
#

It does not have it, do I add it?

deep ingot
#

Yep, add it in. It shouldn't have one by default - its just a box ๐Ÿ˜›

ancient vine
#

xd

#

I added it

deep ingot
#

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 ๐Ÿ˜›

ancient vine
#

there is but it doesn't have anything

deep ingot
#

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.

ancient vine
#

ok

#

why? so we see the same?

deep ingot
#

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.

ancient vine
#

i've put it in front of it

#

if you click "offset" you can set it up with the gizmo

deep ingot
#

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.

ancient vine
#

so, the action does not appear

deep ingot
#

Yep, one seconf. I'm missing something.

#

Weird. I just tried what I had eariler and nadda. Give me a few more seconds ๐Ÿ˜›

ancient vine
#

dont worry

deep ingot
#

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 ๐Ÿ˜›

ancient vine
#

it is an adiccional action?

#

I cant find it

#

inside of scripteduseraction?

#

yep

deep ingot
#

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

ancient vine
#

and we only have one

#

in your case the poop one

deep ingot
#

Correct, and mine is poop

#

Yep

#

poop is my default var, super easy to type ๐Ÿ˜›

ancient vine
#

it is tiny as f...

deep ingot
#

Move the visablity range up?

#

Did you offset it into obvlivion ? ๐Ÿ˜›

ancient vine
deep ingot
#

Yours looks diffent then mine.

#

I dont have a viewing angle

ancient vine
#

cause you have the omnidirectional

deep ingot
#

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.

ancient vine
#

yes, I dragged it

deep ingot
#

Rgr.

ancient vine
#

yeap

deep ingot
#

And its still small?

ancient vine
#

yep

#

even with omnidirectional

deep ingot
#

I wonder if it has anything to do with not having textures on your flags as well

ancient vine
#

something's different?

deep ingot
#

You have the timer up, and the numbers look like eden or error.

#

Oh poop, we also need the faction manager

#

No sides.

ancient vine
#

ok, dragged it

deep ingot
#

See if that resolves your problems.

ancient vine
#

seems like the same

deep ingot
#

Did you give the UI info any text in yours?

ancient vine
#

yeap

deep ingot
#

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

ancient vine
#

oh, action title?

#

I see some thing missing

deep ingot
#

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.

ancient vine
#

it doesn't seem that small anymore

deep ingot
#

Horray.

#

Le peite poo poo

ancient vine
#

eh?

ancient vine
deep ingot
#

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

ancient vine
#

oh ok

deep ingot
#

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.

ancient vine
#

knew that atleast

deep ingot
#

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.

short jay
#

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.

deep ingot
#

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

ancient vine
deep ingot
#

Thoes I think are weapons.

#

Sign_Supply will work.

ancient vine
#

it has the sign xd

deep ingot
#

SCR_ResourceComponent is what gives you the "Supply" system

ancient vine
#

but yeah

#

ok

deep ingot
#

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.

ancient vine
#

like OOP, right?

deep ingot
#

Yep. This is "C/C++ ish"

deep ingot
#

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.

ancient vine
#

ok

deep ingot
#

Replication is server code to update clients (players) but ignore that for now ๐Ÿ™‚

ancient vine
#

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?

deep ingot
#

# 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)

ancient vine
#

oh, ok

deep ingot
#

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

ancient vine
#

so the #ifdef and ifndef takes this code off the loop until something happens?

deep ingot
#

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.

ancient vine
#

ok... and what if I want it to run a script that I made?

deep ingot
#

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.

ancient vine
#

you dont use ctrl + t to use a template?

#

or I have to do it manually every time?

deep ingot
#

oh shit, didn't even know about that ๐Ÿ˜›

#

I just copy and paste from things that work and modify them.

ancient vine
#

we are both learning at least

deep ingot
#

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.

ancient vine
#

casting?

deep ingot
#

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.

ancient vine
#

I meant that I didnt know what casting is, but I think now I have an idea of what it is

deep ingot
#

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.

ancient vine
#

so it inherit the variables values?

deep ingot
#

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?

ancient vine
#

the child get the params of the parent but no viceversa

deep ingot
#

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.

ancient vine
deep ingot
#

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.

ancient vine
#

Ok

deep ingot
#

Anyways. I think you kinda get it. Enough to explore and learn ๐Ÿ™‚

ancient vine
#

yea, I have to lookup the C tutorials from microsoft

deep ingot
#

Somewhat yes, or at least read the BI wiki on keywords in scripting

ancient vine
#

at least to learn some things

deep ingot
#

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.

ancient vine
#

I just have kinda of a idea to test all this "walkthru" you gave me

deep ingot
#

Yep, and a working game world to do it in ๐Ÿ˜›

#

That took me like a week on my own

ancient vine
#

try to make a button inside (or outside) of a car that makes it blow up

#

should be "easy"

deep ingot
#

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

ancient vine
#

gotta find what holds the vehicle hp and set it to something like "-1"

deep ingot
#

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 ๐Ÿ™‚

ancient vine
#

yes, but what triggers the explosion is the armor getting to 0

ancient vine
deep ingot
#

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

ancient vine
#

ok good to know then

deep ingot
#

Have fun

ancient vine
#

thank you, again

deep ingot
#

Hehehe. Help is thanks in what language?

ancient vine
#

I was distracted

deep ingot
#

Ah then disregard ๐Ÿ˜›

ancient vine
#

idk why I writed help

deep ingot
#

Np. I was looking forward to learning something cool ๐Ÿ˜›

ancient vine
#

๐Ÿ™‚

deep ingot
#

Intro to Scripting: Getting started/Making a button

sage nacelle
#

basic oop and script knowledge is enough imo

ancient vine
#

thing is I got the logic of programming, but 0 sintax knowledge of C

sage nacelle
#

nice, logic (and will) is all that matters imo

ancient vine
#

then its just copy and paste

#

?

sage nacelle
#

kinda depend on your field, you can get by with adapting copy pasta

ancient vine
#

I should be able to do things then

sage nacelle
#

for sure

#

only the first 1k hours of modding is painful so thats pretty easy to get in