Jump to content
austin_medic

Problem adding things into listboxes

Recommended Posts

So I'm having a bit of an issue with my dialog, I can get it to display and all that, but I am trying to get it to populate both listboxes with various objects, and it seems no matter what I do it doesn't work.... I debugged the adding of objects to the listbox with hints and the entire array of objects is iterated through fully with no errors, still nothing gets added to the Listboxes.

 

init.sqf

player addAction["Open",{createDialog "ropeSystem";}];


AUSMD_ropeSystem_load =
{
_vehs = nearestObjects[(getPos player),["Car_F"],15]; //vehicle to tow other things in the vicinity.
{
lbAdd [150010,typeOf _x];
lbSetData [150010,_foreachIndex,_x];
} forEach _vehs;
_objects = nearestObjects[(getPos player),[],15]; //this would be a list of acceptable objects to drag around.
{
lbAdd [150011,typeof _x];
lbSetData [150011,_foreachIndex,_x];
} forEach _objects;
};


AUSMD_ropeSystem_detach = 
{
_veh = _this select 0;
_obj = _veh getVariable "AUSMD_ropeSysAttach_obj";
_rope = _veh getVariable "AUSMD_ropeSys_rope";


ropeDestroy _rope;


_obj setVariable ["AUSMD_being_dragged",false,true];
_veh setVariable ["AUSMD_ropeSysAttach",false,true];
_veh setVariable ["AUSMD_ropeSysAttach_obj",nil,true];
_veh setVariable ["AUSMD_ropeSys_rope",nil,true];


hint "rope detached...";
};




AUSMD_ropeSystem_attach =
{
_veh = lbCurSel 150010;
_obj = lbCurSel 150011;
if(_veh == -1 || _obj == -1) exitWith {hint "No Selection";};
_vehR = lbData _veh;
_objR = lbData _obj;


if(_objR getVariable "AUSMD_being_dragged" || _vehR getVariable "AUSMD_ropeSysAttach") exitWith {hint "Vehicle or Object already being towed.";};
_rope =  ropeCreate [_objR,_veh,[0,0,0.2],15];
_objR setVariable ["AUSMD_being_dragged",true,true];
_vehR setVariable ["AUSMD_ropeSysAttach",true,true];
_vehR setVariable ["AUSMD_ropeSysAttach_obj",_objR,true];
_vehR setVariable ["AUSMD_ropeSys_rope",_rope,true];


hint "attached";
};


myRope.hpp

class RopeSystem
{


idd=-1;


movingenable = false;


onLoad = "[] call AUSMD_ropeSystem_load";




class controls


{


class attachRope: RscButton
{
onButtonClick = "[] call AUSMD_RopeSystem_Attach";
idc = 160010;


text = "Attach Rope"; //--- ToDo: Localize;
x = 0.375313 * safezoneW + safezoneX;
y = 0.598 * safezoneH + safezoneY;
w = 0.0984375 * safezoneW;
h = 0.07 * safezoneH;
};
class detachButton: RscButton
{
onButtonClick = "[cursorTarget] call AUSMD_RopeSystem_Detach";
idc = 160011;


text = "Detach"; //--- ToDo: Localize;
x = 0.539375 * safezoneW + safezoneX;
y = 0.598 * safezoneH + safezoneY;
w = 0.0984375 * safezoneW;
h = 0.07 * safezoneH;
};
class vehattachText: RscText
{
idc = 100100;


text = "Veh to Attach To"; //--- ToDo: Localize;
x = 0.355625 * safezoneW + safezoneX;
y = 0.304 * safezoneH + safezoneY;
w = 0.13125 * safezoneW;
h = 0.042 * safezoneH;
};
class objectAttachingText: RscText
{
idc = 100101;


text = "Object your Attaching"; //--- ToDo: Localize;
x = 0.519688 * safezoneW + safezoneX;
y = 0.304 * safezoneH + safezoneY;
w = 0.144375 * safezoneW;
h = 0.042 * safezoneH;
};
class titleBar: RscText
{
idc = 100103;


text = "AUSMD - Rope Attachment System"; //--- ToDo: Localize;
x = 0.335938 * safezoneW + safezoneX;
y = 0.234 * safezoneH + safezoneY;
w = 0.34125 * safezoneW;
h = 0.056 * safezoneH;
colorBackground[] = {0,0,0,1};
};
class vehicleAttachment: RscListbox
{
idc = 150010;


x = 0.362187 * safezoneW + safezoneX;
y = 0.36 * safezoneH + safezoneY;
w = 0.124687 * safezoneW;
h = 0.224 * safezoneH;
};
class ObjectAttachment: RscListbox
{
idc = 150011;


x = 0.52625 * safezoneW + safezoneX;
y = 0.36 * safezoneH + safezoneY;
w = 0.124687 * safezoneW;
h = 0.224 * safezoneH;
};


};
};




 

Share this post


Link to post
Share on other sites

From what I can tell, there seems to be a positioning error, possibly with "_objects". (You may need to have it at the very top of the ".sqf" file)

 

 

There should be an error displayed in the ".rpt" log, it will give a further explanation on the actual issue.

 

 

Also, you have an undefined variable, "_foreachIndex".

Share this post


Link to post
Share on other sites

_forEachIndex is a variable that represents the current index of the array being evaluated by the forEach command (unless its borked, even then no script errors). 

 

I will take a look at the .rpt log and see what that turns up

Share this post


Link to post
Share on other sites

First of all, working with IDCs and IDDs inside SQF scripts, I always recommend to use #defines to make yourself sure you're always using the correct number, because otherwise debugging might get really messy.
 
Secondly, please indent your code for readability reasons, because debugging here

if (true) then {
    if (true) then {
        if (true) then {
            if (true) then {
                if (true) then {
                    if (true) then {
                        if (true) then {
                            //do something here
                        };
                    };
            };
        };
    };
};

is much easier than here

if (true) then {
if (true) then {
if (true) then {
if (true) then {
if (true) then {
if (true) then {
if (true) then {
};
};
};
};
};
};

As for your lbSetData, I'd recommend you to use the following syntax to make sure, you're adding the stuff in the correct place:

{
    lbSetData [150011, lbAdd [150011, typeof _x], _x];
} forEach _objects;

Share this post


Link to post
Share on other sites

 

First of all, working with IDCs and IDDs inside SQF scripts, I always recommend to use #defines to make yourself sure you're always using the correct number, because otherwise debugging might get really messy.

 

Secondly, please indent your code for readability reasons, because debugging here

if (true) then {
    if (true) then {
        if (true) then {
            if (true) then {
                if (true) then {
                    if (true) then {
                        if (true) then {
                            //do something here
                        };
                    };
            };
        };
    };
};

is much easier than here

if (true) then {
if (true) then {
if (true) then {
if (true) then {
if (true) then {
if (true) then {
if (true) then {
};
};
};
};
};
};

As for your lbSetData, I'd recommend you to use the following syntax to make sure, you're adding the stuff in the correct place:

{
    lbSetData [150011, lbAdd [150011, typeof _x], _x];
} forEach _objects;

1. My code is always indented in notepad++, this forums simply gets rid of any formatting that was done to the text in the first place and I only get about 5 minutes to put a post up before it logs me out for inactivity so taking the extra time to reformat the whole thing again is simply not feasible.

 

2. That code is nice and all, but did not solve the issue itself. 

 

3. .rpt file shows no information regarding any kind of error at all, debugging with hints shows it should be adding everything to the listboxes, but it simply does not appear to do so.

Share this post


Link to post
Share on other sites

1. My code is always indented in notepad++, this forums simply gets rid of any formatting that was done to the text in the first place

Strange, I copy-paste my code from Npp, too and it works.

 

I only get about 5 minutes to put a post up before it logs me out for inactivity.

Yeah, they removed the "Remember me" checkbox, though I haven't had inactivity problems yet. Maybe, ask a person in charge what the issue might be.

 

Anyway, regarding the actual issue:

Unfortunately, I can't test right now, but before you do all that stuff to your dialog, make sure it is generated completely before starting to add stuff. Meaning simply give it a waitUntil or a sleep of 1 or 2 seconds after the execution of the "createDialog" line and make sure you wait until the dialog is created, so give it an IDD so you can check that. So somewhat like this:

player addAction["Open", {
  [] spawn {
    createDialog "ropeSystem";
    waitUntil {!isNull findDisplay 151000;}; //151000 = example IDD
    [] call AUSMD_ropeSystem_load; //remove this line from the dialog's onLoad
  }
];
Edited by Heeeere's johnny!

Share this post


Link to post
Share on other sites

2) he isn't adding anything to the dialog in the init.sqf, just defines the functions.

 

But I agree; you should try changing the onload EH (AUSMD_ropeSystem_load) from call to spawn and add some sleep/waituntil there. If I remember correctly, I had the same problem once.

Share this post


Link to post
Share on other sites

2) he isn't adding anything to the dialog in the init.sqf, just defines the functions.

 

Oh, sorry, corrected that. Yeah, I seemingly didn't pay too close attention to the code as I was too busy thinking about the missing indention, sorry for that. But yeah, waitUntil and such...

 

Also, as I just see it, instead of "Car_F", simply use "Car" in your "nearestObjects" line. I don't know if "Car_F" exists as class, but "Car" works for sure. Similarly do "Air" (helicopters/planes) and "Ship" (boats/ships).

Share this post


Link to post
Share on other sites

Well hilariously it now works with the sleep, I tried that before and it didn't work. 

Share this post


Link to post
Share on other sites

Whether or not it works with "sleep" depends on how long it takes for the dialog to be created before the SQF goes on. I discourage from using "sleep" for that purpose, because this might fail in many cases, e.g. if the sleep is too short or your machines load is at some point higher than it usually is, which might result in that very behaviour, namely that it works in one moment, but not in the other despite the exact same code.

Share this post


Link to post
Share on other sites

Did you change the call to spawn? If you called it before, and it ran in a non-scheduled environment then the sleep/waituntil didn't have any effect.

In that case, I assume you didn't have -showscripterrors enabled? Because you would have seen the error.

 

EVERYBODY should have it on at all times! :)  Scripters obviously, but also players, because if some error pops up you'll know things aren't probably working as intended and your mission may be ruined later on.

  • Like 1

Share this post


Link to post
Share on other sites

I did have show script errors on, I changed call to spawn earlier and it literally did not work and It gave me absolutely no errors at all to work with, anyhow doesn't matter now it works (sort of, found a little fail with syntax in the attach function and still has a few kinks)

Share this post


Link to post
Share on other sites
 

Whether or not it works with "sleep" depends on how long it takes for the dialog to be created before the SQF goes on. I discourage from using "sleep" for that purpose, because this might fail in many cases, e.g. if the sleep is too short or your machines load is at some point higher than it usually is, which might result in that very behaviour, namely that it works in one moment, but not in the other despite the exact same code.

I agree with everything here. However, there is an easy fix:

onLoad = "uiNamespace setVariable ['RopeSystem_dialog', (_this select 0)]; [] spawn AUSMD_ropeSystem_load";
AUSMD_ropeSystem_load =
{
    waitUntil {!isNil {uiNamespace getVariable ["RopeSystem_dialog"];};
    //other code
};

As a side note:

I only get about 5 minutes to put a post up before it logs me out for inactivity

Back in the old forum, I would get logged out after about 15 minutes. I found this highly annoying and looked for answers anywhere so that I could just stay logged in permanently, I believe I've even mentioned my plight to a few other scripters either through teamspeak or steam chat. But, now since the change, I'm being kept logged in permanently. It's glorious, I rejoice daily. (I STILL WANT MY BLACK COLOR SCHEME BACK THO)

 

Anyway, there's an easy fix for this too:

Switch back to the forum and press F5 while you're typing, young one, as I had to for many many months. Welcome to hell

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×