Calling upon an updated variable value from within void loop

Hello,

I am trying to make a form of counter, that when reaching certain values will trigger a question to appear on the LCD. The counter variable is defined at the top, and then called upon in void loop() so that the counter is always active. However, when I go to call upon the counter in void questions() it will take the initial int counter = 0 value rather than the updated value inside of void loop(). Is there any way to call upon this value outside of void loop()? Or a different solution that might work better?

Kind of a massive code noob so please don't be too technical, thanks!

Code below:

// include the library code for LCD
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


//COUNTER VARIABLES
// These constants won't change:
const int analogPin = A0;    // pin that the sensor is attached to
const int ledPin = 13;       // pin that the LED is attached to
const int threshold = 1;   // an arbitrary threshold level that's in the range of the analog input

int counter = 0;
int life = 81;
int analogValue;

void setup() {

 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
//
//  analogValue = analogRead(A0);

 //COUNTER STUFF
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);
 // initialize serial communications:
 Serial.begin(9600);

questions();
}

void loop() {

 //COUNTER
 // read the value of the potentiometer:
 analogValue = analogRead(analogPin);
 //Serial.println(analogValue);
// if the analog value is high enough, turn on the LED:
 if (analogValue > 900) {
   digitalWrite(ledPin, LOW);
   counter ++;
   delay(500);
 } else {
   digitalWrite(ledPin, LOW);
 }
 //Print the counter
//  Serial.println(counter);
//  delay(1500);

 //QUESTIONS
 lcd.setCursor(0,0);
 lcd.print("Do you Smoke?");
 lcd.setCursor(0,2);
 lcd.print("1. No 2. Yes");

//  if(counter >= 2){
//    life = life - 10;
//    Serial.println(life);
//    delay(5000);
//
//  } else{
//    Serial.println(life);
//    delay(900);
//  }

 
//  lcd.scrollDisplayLeft();
//    delay (700);

 
}

void questions(){

   delay(200);
   if(counter >= 2){
   life = life - 10;
   Serial.println(life);
   delay(1000);

 } else{
   Serial.println(life);
   delay(1000);
 }
}

Hi, please be kind to update your post with code tags. See "How to use the forum" for that and many more.

But how do you know your conclusion is true? You NEVER call the function questions() so it's not executed, ever.

Added code tags, sorry!

I have originally called upon questions in the setup, due to playing around with the code loads its been removed/readded various times. Forgot to add it back in for this post, my bad. Updated now. I have tested it because in the questions function I have serial printed the counter, which is consistently at 0.

calling a value does not mean much. You just work with a value such as what you do in

if(counter >= 2){

. This part of the code is in a function

void questions()
{
  ...
}

and for this to be triggered you need to ensure you call the function from the loop() (if you want it to be called regularly) or from the setup() if you want it to be called once at start-up.

calling a function is no different than what you do with analogRead() or digitalWrite(), you just need to call questions(); in the right place.

counter being a global variable (if you take care of defining it only one, read about variable scope), you'll see the current value of counter either in setup(), loop() or question()

EDIT: was typing as you provided an update.

Updated now. I have tested it because in the questions function I have serial printed the counter, which is consistently at 0.

I am not sure what you have updated, but the code in the original post still only calls the questions() function from setup() so it will only ever run once each time the Arduino is reset at which point counter will have a value of zero

I've tried it in both setup and loop.

It doesn't work in loop as I don't want questions to continuously loop as it will then continue to -10 off of life, which I only want it to do once. However, if I put it in setup and add a delay into questions (so that the counter has time to be more than 2 and therefore run the if function), it never runs the life - 10 part meaning that the counter value it is receiving is never above 2. However if I run the same code and print the counter from within the void loop it is reaching above 2. Meaning that it isn't reading the counter from within the void loop and instead the defined variable at the start of the code.

if questions() is called once (from the setup()) then whatever is in there will be executed only once...
if you want to execute multiple times but not remove 10 from your life at every spin of the loop() then you need to code additional logic that decides when to do that.

I think it's time for taking a step back and write in plain english what you are trying to achieve, when does the counter needs to increment, when does the question need to pop-up, when are you removing 10 points from the life.