Sunday, February 28, 2016

Creating a Listbox ARMA 3 part 2

It's been awhile since my last post. I apologize, I work as an Test Engineer in a manufacturing plant. My time is spent working the in the plant day in and day out. My hobbies got pushed to the side a good bit. Anyway let show you guys how to do some magic with list boxes. This should be a quick one as it there isn't much to setup.




Read my last blog post if you want to know how to get this far. For the rest who have followed the last post, you will see that I added more entries in the list box. This is easy to do and I'm sure you know how to do it. Now it's time to show you how to add the magic to make your selection do a certain action.

1. Open up RangeGUI.hpp and go to the class Rex_Ok: RscButton. We will add this line of code.

  • action = "[] spawn {execVM 'listboxAction.sqf';};";


The code basically executes a script every time the OK button is pressed. For the Cancel button add this line.
  • action = "closeDialog 0;";





The code in this class will close the Dialog all together.

2. Create a file listboxAction.sqf

This file will be used to perform the action we want when the OK button is pressed. There isn't to much we have to add to this file. What is important in this file is the action lbCurSel.

https://community.bistudio.com/wiki/lbCurSel 

Go to the link to learn more but for this tutorial purposes I'll keep it simple. What lbCurSel returns is a number or rather the index which the list box cursor was when the OK button was pressed.


As you can see depending on the where the cursor was located when the OK button was pressed it will have an index which we can retrieve to use to perform a certain action. Now looking at lbCurSel 447. The number 447 isn't an arbitrary number, it actually refers to the list box defined in the class Rex_Range or RangeGUI.hpp. Refer to my previous blog posts to see where it is defined. If you're new to programming there is one thing I need to make you aware of. Even though there is a list of items 1 to 4. Computers start the count at 0. As you can see in the code I made hints to reflect this. This very important you remember this as it can be a headache when the logic is right in your head but no the computers.

3. Click index 2 and press OK




As you can see index 2 is the third item in the list.

Conclusion

So this blog post is showing you how to retrieve user selection from the list box to perform an action. You can do a lot more than showing hints. You can actually make a person teleport or spawn a vehicle. There is plenty of things you can do if you have the right tools in your tool box. When I first started to learn Arma Scripting. Everything I did was attached to a pole. Having over 4 options on a pole is very hard to select the right choice. A list box is better for the user experience and easier to code. Using addAction command is a hassle. Well I hope my instructions were clear. Let me know if you get stuck.



Tuesday, November 17, 2015

Creating a Listbox ARMA 3

I know it has been a long while since I've updated this but I got a job so I'm super busy. Between work and keeping my girlfriend happy there isn't much time for personal development. So lets get to it.

Listbox, what is it? what does it do? 

A listbox basically presents text in a nice little box that is organized but with extra features. For example depending on what you select it can create an event to happen. For this tutorial I'm going to show just how to create one and add something to the list. I'm not going step by step in creating one like I did in my previous post "G.U.I Button ARMA 3 Style". If you are ever lost or need a refresher refer to that post and catch up.

1. Start up ARMA 3 and select Editor and select any map it doesn't matter and create a new mission.

2. Save the mission. It can be anything you want but remember the name.

3. Once you save it, place one playable unit down and click preview.

4. Inside the game press escape and look for GUI EDITOR on the bottom and select it.

5. I'm going to skip ahead and not break it down Barney Rubble style on how I created the listbox. But I will show you what it looks like.


This is what I created using the GUI editor. I added a RscFrame, RscListBox, 2 RscButton, and RscText.

6. Now once I created this I need to save the information. Shift + Ctrl + S, paste this information into a empty text document. Hopefully you are using Notepad++. Save it any name you want and you're almost done. I named my file RangeGUI.hpp. Eventually I want to create ranges on the island of Stratis.


This is what it looks like after I made changes. Remember from my last post I had to add a couple of hings to make this work. Take a look at the comments in the picture for more information.


7. Now to get the listbox to work correctly I had to add a couple of things to this. Noticeably is the onLoad command. This basically tells ARMA 3 whenever this dialog is created load this script. rangeScript.sqf is what makes the listbox to work. Pay attention to the idd variable and the idc variable under Rex_Title.

8. Now in the description.ext I have to define the parent config and my config so ARMA can display the listbox.

9. Now I create a sqf file called "rangeScript.sqf". In this file I basically add text to the listbox. Look in the comments in the picture for more details.

10. Hopefully the picture above explains how to make the listbox works. Basically I have to find the display. I used the findDisplay command and give it the idd number 2017 which I defined. Once I have the display I need access to the control for the listbox. Using displayCtrl command I passed the idc number I defined for the listbox. Refer to the pictures in case you're confused. displayCtrl returns a control data type which gives me more access to the listbox. Now I need to add something to the listbox. lbAdd command is what I used to add a simple text to the listbox. To add further flare to the text I set the color to green. Refer to the picture above for more details.

11. Now that script is defined it is time to test it out. Load up the mission and place down a unit you can control and a pole and edit the initialization of it to this.
12. Preview the mission and run straight to the pole and activate the addAction. You should see something similar to this.

So far nothing has been added to make anything to happen, basically the box is there. I'll show you in the next tutorial how to make the magic happen.

This concludes this tutorial.

Tuesday, April 28, 2015

G.U.I Button ARMA 3 Style

I love the ARMA series for one good reason, it allows custom scripts or mods. It's a sandbox game that is based off my personal career in the National Guard. That skill is combat but enough about me let me tell you my history with this game. I started to play this game because I remember my late twin brother was playing ARMA Gold and I happen to see ARMA II Combined Ops at Wal-Mart and at that moment I decided to  pick it up. I was trying to get closer to my brother after his death in Afghanistan. Well it was the best decision I made because it gave me the desire to code and develop. I found the gift of developing and I have been increasing my development skills ever since. So my blog will basically be my personal development with Java and other languages but also ARMA 3 content. So to get back on course I want to talk about ARMA's use of G.U.I's. With ARMA I feel it is harder to learn G.U.I.'s or dialogs as the game calls it. I took me weeks to learn how to create a button and I hope by sharing my success others will fare a lot easier than me. I'm going to list the steps to get one button to write a message on screen.
1. Start up ARMA 3 and select Editor and select any map it doesn't matter and create a new mission.

2. Save the mission. It can be anything you want but remember the name.

3. Once you save it, place one playable unit down and click preview.

4. Inside the game press escape and look for GUI EDITOR on the bottom and select it.

5. Press escape and you should now be in the GUI EDITOR you should have a grid in front. A few tips, pressing 'H' brings up the help menu and it tells you all the commands needed to operate the editor.

6. Right-click anywhere and a dialog will pop up, select RscButton near the top and watch it appear on your screen.

7. Right-click on that button and another menu pops up and this menu allows you to edit the button to your liking.



8. I'll go through what I've done

  • Class: This is the variable name to refers to this button
  • Text: This will appear on the button
  • Text color: This will be the color of the button.
    • Look at Active color and to see what each value means. It's a RGB scale with Alpha
  • Tooltip: When a mouse hovers over the button a this text will appear.
  • Position type: Always put Safezone, I don't know why but all tutorials I've read say so.
9. Click okay and you're almost ready. Now you have to save your script. But first you have to export your parent classes. This is needed and you'll see why in a minute.  Press 'H' and look for export Parent Class.


As you can see it's Ctrl + P. This will copy information to your clipboard. Alt tab out of the game and open up any text editor preferably Notepad++, and paste the information inside a text document. You should see something like this.


10. Now save this file as defines.hpp Now go back in the game and look for Export to config format. It's Shift + Ctrl + S. This will ask you to name the project and you can name it anything. Once it is saved it will also copy to your clipboard. So open up a new file and paste it.


11. As you can see some of the information I posted in the game is here in the document. Now we have to add a few more lines of code. Look at the next picture and you can see what I had to add to make this button work.

12. I had to make class RJ_Example_Button: RscButton a subclass of class controls which is a subclass of class RJ47_Example. Read the comments in the picture to learn more. Make sure to add action line to the button config. It is important as nothing will happen if you don't define that.

13. Save the file as button.hpp. Now open up the mission folder which it should be in this directory
C:\Users\Ramon\Documents\Arma 3 - Other Profiles\yourusername\missions\RJ47_Example.Stratis
Now this is my file path to my mission and we need to save both defins and button.hpp in this folder.

14. After we saved these files we need to create a new file inside this directory and call it description.ext


These are the files you should have inside the directory.

15. Open up description.ext and add 2 lines of code. The ordering is important.

  1. #include "defines.hpp" 
  2. #include "button.hpp"

16. Now save this file and head back into ARMA 3 and lets spawn the button. Add a pole to the mission and edit the initialization block of the pole and add this code
  • this addAction["Spawn G.U.I.",{createDialog "RJ47_Example";}];

17. Click okay, save it, then preview the mission and head towards the pole and you should see your addAction title show up by looking at the pole. Select this and then boom your button is spawned on the screen. Now nothing will happen until you click your button. Click it and the message will spawn that was defined in the action code in the button.hpp.






This concludes this tutorial.