Home   Help Search Login Register  

Author Topic: Passing / Counting Global variables [SOLVED]  (Read 1423 times)

0 Members and 1 Guest are viewing this topic.

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Passing / Counting Global variables [SOLVED]
« on: 16 Sep 2012, 05:50:53 »
I'm trying to a lot the player with a limited number of items and then remove them each time he uses one. My process is so simple, it should work but it is not working for some odd reason.

My process is
Declare the global variable in the mission Init
Itemsleft = 3

Through a dialog interface, a button executes the script.
Code: [Select]
? (Itemsleft < 1) : hint "You have exhausted your item supply/n Find a facility to restock"; exit

? (Itemsleft > 2) : Itemsleft = Itemsleft -1; hint "You have 2 items remaining in your inventory"; exit

? (Itemsleft < 3) : Itemsleft = Itemsleft -1; hint "You have 1 item remaining in your inventory"; exit

? ((Itemsleft < 2) && (player distance facility >= 1000)) : goto "confirm"

? (Itemsleft < 2) : Itemsleft = Itemsleft -1; hint "You have used the last item in your inventory"; exit

exit

I've searched the forums and the code I am finding looks the same or similar to what I have. But when I execute the script, it simply exits as if none of the conditions are met. Am I not grabbing the global variable correctly or am I just going about it all wrong?
« Last Edit: 17 Sep 2012, 07:16:26 by savedbygrace »

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: Passing / Counting Global variables
« Reply #1 on: 16 Sep 2012, 08:41:54 »
Ok, I've had a little playaround with it, and I made a couple of changes. The way I called the script is a little different to how you called it, as in I haven't made a dialog interface. Instead, I called it via an ol' fashioned addaction (which is a form of interface).

I believe it is working as it should be. Everytime the player uses the action, the itemsleft variable decreases by 1 each time. If I get some time later I'll try making a quick dialog and trying it out on there.

Here is the working script (at least when using addaction):

Code: [Select]
? (Itemsleft == 0) : hint "You have exhausted your item supply. Find a facility to restock"; exit

? (Itemsleft == 3) : Itemsleft = Itemsleft -1; hint "You have 2 items remaining in your inventory"; exit

? (Itemsleft == 2) : Itemsleft = Itemsleft -1; hint "You have 1 item remaining in your inventory"; exit

? (Itemsleft == 1) : Itemsleft = Itemsleft -1; hint "You have used the last item in your inventory"; exit

;wasn't sure where to put this, or whether it would need changing
? ((Itemsleft < 2) && (player distance facility >= 1000)) : goto "confirm"
exit

I got rid of some of the < and > signs and replaced them with ==. As we're dealing with whole numbers, it seemed less confusing to me to use == signs instead, as the variable decreases by 1 each time.

Code: [Select]
itemaction = player addaction ["Take Item","inventory.sqs"]
^ That was how I called the script.

You could try using 'if', 'then', and 'and' commands to see if it makes any difference, but I can't imagine it doing so (but, consider every possibility)

Hope this helps
Gruntage

ADDITIONAL: I've attached a small missionette for you, with a simple dialog interface that I grabbed from another mission. I didn't change the dialog at all, so it's still in the format of a difficulty selection dialog. You can bring the dialog up by using 0-0-1. Select the EASY option. I didn't have much time so I didn't make any changes to the dialog appearance. Hope you find it useful.
« Last Edit: 16 Sep 2012, 08:57:02 by Gruntage »
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Passing / Counting Global variables
« Reply #2 on: 17 Sep 2012, 05:45:50 »
I've used the equal to idea as well as If Then statements and a few other ideas that I borrowed from other counting scripts but nothing seemed to work. I don't think the global variable was being passed to the script somehow because if I changed the conditions to something like "getdammage player whatever" the hints would display. I'll attempt your sample and see if it works. Could be that I was overlooking something else. I'll keep you posted and thanks for the speedy response pal.

EDIT:
Oh My good loving Lord! You would not believe the idiotic mistake that I overlooked for 3 days!!! Your code worked fine as did the various other code snippets that I had implemented before, Once I moved the global variable to the unit init. This puzzled me and so I looked at my Init file and discovered that it was an EXT file. I had forgotten that I copied the description file and erased the content to save time in creating a new sqs file. It ended up costing me 3 days of frustration but at least it earned me the dunce award.

I am so freaking relieved that I can press forward to my next task. Thanks for the support Gruntage!!!!!
« Last Edit: 17 Sep 2012, 07:16:01 by savedbygrace »

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: Passing / Counting Global variables [SOLVED]
« Reply #3 on: 17 Sep 2012, 08:27:12 »
LOL. Not to worry SBG, even the most experienced editors make mistakes sometimes.
« Last Edit: 17 Sep 2012, 09:36:42 by Gruntage »
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba