Results 1 to 4 of 4

Thread: How do I access variables from_ctf in _killcam?

  1. #1
    ... connecting
    Join Date
    Jan 2024
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do I access variables from_ctf in _killcam?

    Apologies if this is a dumb question, I'm a java developer by trade, this may just be me not understanding c++ that well.

    I am trying to create a simple mod, disable killcam if a player is killed and their flag is not at base - since then you can use killcam to find the flag carrier.

    I noticed the _ctf script file has self.flag.atbase and other.flag.atbase. So first step is to see if I can access those values.

    To _killcam I added:

    Code:
    	if(isdefined(allied_flag.atbase)) 
    	{ 
    		  println( "DEBUG: self flag exists" ); 
    		  println( "DEBUG: self flag value" ); 
    		  
    		  if (allied_flag.atbase)
    		  {
    			println( "DEBUG: self flag value is TRUE" ); 
    		  } else
        	  {
    			  println( "DEBUG: self flag value is FALSE" ); 
    		  }
    	} else {
    		println( "DEBUG: self flag does NOT exist" ); 
    	}
    It returns error:
    uninitialised variable 'allied_flag'

    I have tried every variable I can think of, they all return uninitialised , which is odd, thought whole point of isdefined is so it wouldn't throw error.

    The most success I've had is with if(isdefined(self.flag)). This does not throw error, but hits my else statement and says it does not exist.

    What am I doing wrong?

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,730
    Thanks
    17
    Thanked 1,081 Times in 683 Posts
    Code:
    allied_flag = getent("allied_flag", "targetname");
    axis_flag = getent("axis_flag", "targetname");
    as jper lines 1051 and 1068 of ctf.gsc
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  3. #3
    ... connecting
    Join Date
    Jan 2024
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you! Of course its that simple. If you are ever in CT I'll buy ya a beer.

    Quick question - so this does what I need to do, but the allied_flag variable already exists in ctf.gsc, just for my full understanding, is it possible to get a variable from a different script?

  4. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,730
    Thanks
    17
    Thanked 1,081 Times in 683 Posts
    Quote Originally Posted by paulb39 View Post
    Thank you! Of course its that simple. If you are ever in CT I'll buy ya a beer.

    Quick question - so this does what I need to do, but the allied_flag variable already exists in ctf.gsc, just for my full understanding, is it possible to get a variable from a different script?
    Variables in gsc are mostly like c/c++, where there scope is limited to the "current function". Within this current function, they can however bleed through to upper levels (stuff created within a for loop will be accessible after the closing bracket of said loop for example)

    To use global variables, you'll need to store them in objects. The global object is called level and is basically a struct where you can - while not overwriting existing stuff - add more variables as you wish. You could store the flag in level.flag_axis = getent("stuff"); and have it accessible anywhere.

    Beware that any function can change these variables though. gsc is very single-threaded, so as long as there's no waits/waittills in your function, you can rest assured that no other functions (unless called from within this function by yourself) will modify the values.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  5. The Following User Says Thank You to IzNoGoD For This Useful Post:

    paulb39 (2nd April 2025)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •