Jump to content

Recommended Posts

Hi. I'm having an issue with the below script/function, the issue is that all additional group leaders that spawn after the first use the same camera as the first groups leader?

 

Quote

/// Cams Function

params ["_group"];

_lead = leader _group;
_text = groupID _group;
_cam = objNull;
_tv = objNull;
_add = [];

tvarray select (tvarray pushBack (tvarray deleteAt 0)) params ["_tv","_add"]; // this works well, tvarray references 8 monitors defined in the init.sqf which are 4 rugged dual screens that I separate using '_tv' for the 'object' and '_add' for the left or right 'screen' of the same monitor e.g [tv1,0],[tv1,1],[tv2,0],[tv2,1] etc etc
_cam cameraEffect ["terminate","back"];
_tv setObjectTexture [_add,"#(argb,512,512,1)r2t(_text,1)"]; // I attempted to use _text (group id name) to create a unique r2t name (and hoped it would be a unique camera name)... it works to a degree but does not prevent the main issue.
_lead lockCameraTo [_tv, [0]];
_cam = "camera" camCreate [0,0,0]; // this line is what I suspect is causing the  issue but '_cam' is local so surely no need to 'camDestroy' to use another camera feed elsewhere?
_cam cameraEffect ["Internal", "Back", "_text"];
_cam attachTo [_lead, [0.35,-0.08,0.08], "neck"];
_cam camSetFov 0.75;


So the first group (alpha1_0) spawns and and the shoulder cam shows on the left screen of the first dual monitor... all good...

 

The second group (alpha1_1) spawns (runs the function separately) and the 'stream' correctly shows (now on the right screen) but its the same shoulder cam as the first group alpha 1_0  (attached to the same group leader) I don't understand??

 

All variables are local aside from tvarray which just chooses next available monitor and i even attempted to create a unique r2t name so each r2t name is alpha1_0 alpha1_1 etc etc.

 

So what have I done wrong?

Also what exactly is 'r2t' there is very little information about what that actually is and same goes for 'turretPath' I cannot find much info on the Biki for that? (turretPath: Array - path to the turret with required camera.... what does that actually mean?)

 

Any help  appreciated.

 

Cheers.

 

Share this post


Link to post
Share on other sites
13 minutes ago, Ramsen IV said:

Hi. I'm having an issue with the below script/function, the issue is that all additional group leaders that spawn after the first use the same camera as the first groups leader?

 


So the first group (alpha1_0) spawns and and the shoulder cam shows on the left screen of the first dual monitor... all good...

 

The second group (alpha1_1) spawns (runs the function separately) and the 'stream' correctly shows (now on the right screen) but its the same shoulder cam as the first group alpha 1_0  (attached to the same group leader) I don't understand??

 

All variables are local aside from tvarray which just chooses next available monitor and i even attempted to create a unique r2t name so each r2t name is alpha1_0 alpha1_1 etc etc.

 

So what have I done wrong?

Also what exactly is 'r2t' there is very little information about what that actually is and same goes for 'turretPath' I cannot find much info on the Biki for that? (turretPath: Array - path to the turret with required camera.... what does that actually mean?)

 

Any help  appreciated.

 

Cheers.

 

I believe this line to be the culprit:

_tv setObjectTexture [_add,"#(argb,512,512,1)r2t(_text,1)"];

Second parameter is a string.

Try this to properly pass _text:

_tv setObjectTexture [_add,format["#(argb,512,512,1)r2t(%1,1)",_text]];

At least that one's sticking out for me, heh. Might do the trick.

 

Cheers

Share this post


Link to post
Share on other sites

Thanks for the reply Grumpy.

 

Sadly the code threw an error:

 

41 minutes ago, Grumpy Old Man said:

_tv setObjectTexture [_add,format["#(argb,512,512,1)r2t(%1,1)",_text]]; // type string expected array (before format)

 

Another error quickly displayed before this one regarding _text but disappeared before I could read and the one above displayed instead... it did not show again?

 

I'm further altering the code you, larrow and few others helped me out with a few years back:

 

This used to create a cam feed on a single screen and then destroy the cam (before creating a new one) every time 'add action' was used to switch between groups, so now I'm trying to create a more automated and lite version using multiple screens but without add action.

 

cheers.

 

EDIT: I spawn the camera function as i need the script that spawns it to complete but i tried 'sleep 5; camDestroy _cam' and so the camera stops following the lead unit, but STILL the new camera just is a copy of the first? So camDestroy does not solve the duplicate issue either. Also here is the tvarray so you know what that refers to: tvarray = [[tv1,0],[tv1,1],[tv2,0],[tv2,1],[tv3,0],[tv3,1],[tv4,0],[tv4,1]]; And the function is spawned thus: [_grp] spawn Cole_fnc_cams;

This might help...

Share this post


Link to post
Share on other sites

Just had a quick glance over it and noticed the same error with "_text" as above (string instead format) in this line:

_cam cameraEffect ["Internal", "Back", "_text"];

Cheers

Share this post


Link to post
Share on other sites

Thanks again for the reply grumpy.

 

Yes, I finally worked that out after several tests and you were 100% correct with your suspicion in your first post.

 

Quote

_tv setObjectTexture [_add,"#(argb,512,512,1)r2t(_cannotDoThis,1)"]; // so i'm stuck on this bit.

 

After tests I found that I cannot use a string nor even a _variable as the value for the setObjectTexture so it has to be along the line of the format code posted above - but perhaps with a value instead of a string. e.g 1, but I cannot in anyway use groupID as the result is a string. If the issue is solved then this will not be a problem as I can simply use an ascending value using '_cannotDoThis = _cannotDoThis + 1' to create a unique value for each group spawned.

 

Quote

_cam cameraEffect ["Internal", "Back", _str]; // i can convert my value to a string

 

As you said grumpy this must be a string but as the setObjectTexture value CANNOT be a string I therefore had to convert the value to a string using str (_str = str _cannotDoThis;) this worked perfectly when converting a predefined value for the setObjectTexture so this line is no longer a problem but the two lines (setObjectTexture & cameraEffect) are entwined.

 

So bottom line is I need someway to solve the _cannotDoThis issue in the setObjectTexture code ...

 

Your 'format' idea was very close but did not work with a string - I suspect it was because i was inserting a string (groups id) into a string? or quotes into quotes if you want to look at it that way, I dont know...but perhaps if I try your format idea with just a value?

 

Anyway, I will try it out latter but any ideas in the meantime will be most helpful.

 

cheers.

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

SOLVED!

 

Yep, was as suspected and pointed out by grumpy and the error line and my suspicion in using a string such as groupID.

 

Here is the now working code:


 

// INIT
numb = 0;
tvarray = [[tv1,0],[tv1,1],[tv2,0],[tv2,1],[tv3,0],[tv3,1],[tv4,0],[tv4,1]];

// Function spawn:
[_grp] spawn Cole_fnc_cams;

// Cams Function

params ["_group"];

numb = numb + 1; // creates unique number for each group

_lead = leader _group;
_str = str numb;

tvarray select (tvarray pushBack (tvarray deleteAt 0)) params ["_object","_monitor"];
_object setObjectTexture [_monitor,format["#(argb,512,512,1)r2t(%1,1)",numb]]; // yay!!
_lead lockCameraTo [_object, [0]];
_cam = "camera" camCreate [0,0,0];
_cam cameraEffect ["Internal", "Back", _str];
_cam attachTo [_lead, [0.35,-0.08,0.08], "neck"];
_cam camSetFov 0.75;

 

So thanks again grumpy for helping, you pointed me to the error and finally I solved it!

 

cheers.

 

p.s does placing a variable (with a value such as 10 or hello) into quotes automatically make that string?? (e.g _value = 10 ; "_value" now a string??)

Edited by Ramsen IV
No need for groupID + spelling + typos
  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Ramsen IV said:

p.s does placing a variable (with a value such as 10 or hello) into quotes automatically make that string?? (e.g _value = 10 ; "_value" now a string??)

 

If I'm tracking, no. A string is a data type that represents text. A variable is sort of like a container that holds a piece of data, of any type. A variable can hold a string, but placing quotes around a variable name doesn't turn its held data into a string. You just create a new string.

_value = 10; //_value is variable name, data assigned is 10, type integer
"_value"; //data, type string, but meaningless sitting in the void like that
_value = "_value"; // _value is still variable name, data assigned is now "_value", type string - original data (10, integer) overwritten

I hope that makes sense. Someone smarter than me might be along to explain it better.

  • Like 1

Share this post


Link to post
Share on other sites

Glad you got it sorted, and posted the solution instead of [solved], heh.

 

As @Harzach stated, string is a data type that can contain text. Variable handles (or identifiers) like _value can hold any data type (like numbers, arrays, code, etc.).

The format command automatically converts any passed variable into string, like so:

_text = "Ten";
_number = 10;
_howToGetTen = {5 + 5};
hint format ["How to get %1(%2): %3",_text, _number, _howToGetTen];

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the explanation guys!

 

BTW the script is far from perfect as issues arise when a 'later' spawned group attempts to take control of another groups 'camera feed' (or more accurate its the setObjectTexture code) the screen just goes black until another later group spawns and takes control of that same 'camera feed'... but i did expect this but of course my first goal was to solve the first riddle!!

 

To partially solve the black screen issue though, i can do two things:

1) If I'm spawning a maximum amount of groups (say 4 groups max) I will have 5 free camera feeds/monitors. So group leader dies > new group arrives and there's always a spare camera feed/monitor for them.

2) For point 1 to work properly though I must use 'camDestroy' upon that group leaders death thus freeing up that camera feed/monitor for the next group - so either some kind of while alive loop, wait until death or just an event handle on the leaders death will solve this. Have not got this far yet...

 

For larger battles where I can have up to 10+ groups its more difficult as I would have to have tonnes of monitors to make sure every spawned group has an assigned monitor - additionally the more PIP's I have the more performance hit they generate so this is prob best for small scale 'high command' type missions. (Although 'high command' usually has preplaced groups attached to the HC module but I could still pass them groups to this camera function - but I think years ago i used to spawn groups continuously and add them to the high command module via script somehow? But not sure if I ever got that to work... it was too long ago to remember.)

 

But anyhow the original issue is now solved!

 

Cheers.

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
Sign in to follow this  

×