Jump to content
Sign in to follow this  
cookies2432

Need help with script attatched to a gui

Recommended Posts

Hello, i'm in the need of help with a script that's supposed to "pick up" an item from the ground (soda for example) and then it will take its classname, check it if it matches any of the variables in an array and if it does it will add a value to that variable. After all of that it will find the pic of that item in the config file (haven't begun with this part yet). After this it will add the picture to a rsclistBox on a GUI (IDC = 1500) and the name of the item (for example, can of soda or whatever it's called).
 
I have begun working on it but i'm getting errors about my function being undefined ?
 
This is my code: 
_itemType = (_this select 0);

call fnc_addItem;

fnc_addItem = {

  private ["_Rice","_Beans","_Water","_Soda"];

          _Rice = "Land_RiceBox_F";
          _Beans = "Land_BakedBeans_F";
          _Water = "Land_BottlePlastic_V2_F";
          _Soda = "Land_Can_V1_F";

  if ({_x == _itemType} forEach ["_Rice","_Beans","_Water","_Soda"]) {
    hint format ["Hello"];
  } else {
    hint format ["RIP"];
  }

  deleteVehicle _itemType;

  hint format ["Rice %1 Beans %2 Water %3 Soda %4",_Rice,_Beans,_Water,_Soda];

};



Any help would be extremly appriciated! :)

Share this post


Link to post
Share on other sites

You are calling fnc_addItem before you define it.

_itemType = (_this select 0);

fnc_addItem = {

  private ["_Rice","_Beans","_Water","_Soda"];

          _Rice = "Land_RiceBox_F";
          _Beans = "Land_BakedBeans_F";
          _Water = "Land_BottlePlastic_V2_F";
          _Soda = "Land_Can_V1_F";

  if ({_x == _itemType} forEach ["_Rice","_Beans","_Water","_Soda"]) {
    hint format ["Hello"];
  } else {
    hint format ["RIP"];
  };

  deleteVehicle _itemType;

  hint format ["Rice %1 Beans %2 Water %3 Soda %4",_Rice,_Beans,_Water,_Soda];

};

call fnc_addItem;

Should do it.

Share this post


Link to post
Share on other sites

You are calling fnc_addItem before you define it.

_itemType = (_this select 0);

fnc_addItem = {

  private ["_Rice","_Beans","_Water","_Soda"];

          _Rice = "Land_RiceBox_F";
          _Beans = "Land_BakedBeans_F";
          _Water = "Land_BottlePlastic_V2_F";
          _Soda = "Land_Can_V1_F";

  if ({_x == _itemType} forEach ["_Rice","_Beans","_Water","_Soda"]) {
    hint format ["Hello"];
  } else {
    hint format ["RIP"];
  };

  deleteVehicle _itemType;

  hint format ["Rice %1 Beans %2 Water %3 Soda %4",_Rice,_Beans,_Water,_Soda];

};

call fnc_addItem;

Should do it.

Oh well, I'm happy it's that simple lol. Sometimes when you focus on one thing you find it hard to spot other things. Thanks a lot! :D

Share this post


Link to post
Share on other sites

That's tunnel vision.

 

Also about your function, I know its early stage, but I suggest using functions via CfgFunctions.

This way you don't have to run the code to create your function every time you pick something up.

Share this post


Link to post
Share on other sites

The script is still not working tho, it says that line 13 (the one with "if" and "forEach" is missing a "  ;  ".

Share this post


Link to post
Share on other sites

That's tunnel vision.

 

Also about your function, I know its early stage, but I suggest using functions via CfgFunctions.

This way you don't have to run the code to create your function every time you pick something up.

Thanks! :D, How would I use it tho?

Share this post


Link to post
Share on other sites

The script is still not working tho, it says that line 13 (the one with "if" and "forEach" is missing a "  ;  ".

 

You are missing a then,

if ({_x == _itemType} forEach ["_Rice","_Beans","_Water","_Soda"]) then {

Share this post


Link to post
Share on other sites

 

You are missing a then,

if ({_x == _itemType} forEach ["_Rice","_Beans","_Water","_Soda"]) then {

Thank you! Now it's giving some weird "reserved variable in expression" error message for some reason, it's about this I think:

if ({_x == _itemType} forEach ["_Rice","_Beans","_Water","_Soda"]

Any idea why? As I understand that's correct usage of forEach but i'm proabably wrong, still learning :). Could it be because i mention the variables twice (private) and in the if statement?

Share this post


Link to post
Share on other sites

Yea you are using "" (quotes), you are trying to point towards these,

_Rice = "Land_RiceBox_F";
_Beans = "Land_BakedBeans_F";
_Water = "Land_BottlePlastic_V2_F";
_Soda = "Land_Can_V1_F";

So remove the "", because if you have "around something" its a string.

Share this post


Link to post
Share on other sites

Yea you are using "" (quotes), you are trying to point towards these,

_Rice = "Land_RiceBox_F";
_Beans = "Land_BakedBeans_F";
_Water = "Land_BottlePlastic_V2_F";
_Soda = "Land_Can_V1_F";

So remove the "", because if you have "around something" its a string.

I thought I had to use a string format since they are classnames :/

Share this post


Link to post
Share on other sites

Thanks! :D I got another issue but I think I can solve it on my own, not sure.it's that it now says "undefined variable" on them. I think I know how to fix it, not sure.

Share this post


Link to post
Share on other sites

I thought I had to use a string format since they are classnames :/

 

Well _Rice is pointing to a string ("Land_RiceBox_F"), and that is a classname, if you use "_Rice" its not a variable anymore, its just a string. Thus not pointing to anything.

Share this post


Link to post
Share on other sites

Well _Rice is pointing to a string ("Land_RiceBox_F"), and that is a classname, if you use "_Rice" its not a variable anymore, its just a string. Thus not pointing to anything.

Yea you are correct, my bad :D. Also, I tried to make them equal to the config paths but it proved, unsucessfull, still having the undefined variable error.

Share this post


Link to post
Share on other sites

Something like this maybe?

//Define the function before we call it??
fnc_addItem = {
  private ["_itemType","_Rice","_Beans","_Water","_Soda","_items"];

  _itemType = _this select 0;
  _Rice = "Land_RiceBox_F";
  _Beans = "Land_BakedBeans_F";
  _Water = "Land_BottlePlastic_V2_F";
  _Soda = "Land_Can_V1_F";
  _items = ["_Rice","_Beans","_Water","_Soda"];
  _pickup = false;


  /* count trought the array until we find the right type */
  {
      if (_x == _itemType) exitWith {
          _pickup = true;
      };
  } count _items;

  if (_pickup) then {
    hint "Hello";
    systemChat format ["Hello: %1",_itemType];
    deleteVehicle _itemType;
  } else {
    hint "RIP";
  }

  hint format ["Rice %1 Beans %2 Water %3 Soda %4",_Rice,_Beans,_Water,_Soda];

};



_itemType = _this select 0;

[_itemType] call fnc_addItem;

Share this post


Link to post
Share on other sites

gives me an error missing " ; ". But  yea something like that, i'm kind of new to scripting but i really want to learn it so i can actually finish my project :D
 

Share this post


Link to post
Share on other sites

Also, i think that this part of the code is not needed (I could be wrong) 

[_itemType]

When I call the function I already have the data from the can (_target = _this select 0) and so because of that, I don't think it's needed to declare it again, however, I could be completely wrong :)

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  

×