.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
Variable scope (Groups : qc : Forum : hard_code() : Variable scope) Locked
Thread Options
numbersix
numbersix quake-c coder++
Nov 26 2017 Anchor

I came across this recently in reference to an issue with the original qcc:

entity scope;		// global var

// now re-use "scope" as a passed parm var
void(entity scope) callfn =
{
	scope.think();		// fails to use passed parm, calls .think() for global scope

};

I will have to test this with fteqcc to see how it is handled. Then report back.


Test code set:

// remove this test code

void() test1 = { bprint("test thought 1\n"); };
void() test2 = { bprint("test thought 2\n"); };

entity scope;

void(entity scope) testfire =
{
	scope.think();	
};
/// REMOVE

void() W_Attack =
{
	local	float	r;

/// REMOVE
	scope = spawn();
	scope.think = test1;

	newmis = spawn();
	newmis.think = test2;

	testfire(newmis);
/// REMOVE

//... rest of attack

};

My version of fteqcc (lets just say modified v1.00) performed thus:

] maphack-glx +map arc_hub

Game is MapHack-Quake using base gamedir id1
MapHack-Quake Linux 02:16:36 Nov 24 2017 v0.6-36-gfd8a17f release
Maphack source code is licensed under GPL 2.0 (see git hub instructions in distro)
Playing registered version.

Server using port 26000
Server listening on address 0.0.0.0:26000
PainKeep 3.0: to vote enter the teleporter for the level you wish to play! 

Connection accepted to local:1
--> client to server keepalive
<-- server to client keepalive

Server: MapHack-Quake build 02:16:36 Nov 24 2017 v0.6-36-gfd8a17f release (progs 45671 crc)

<===================================>

Archon Hub

_-=*[Six] dropped in for tea

PainKeep 3.0: to vote enter the teleporter for the level you wish to play! 

You got the Super Nailgun
test thought 2
test thought 2

Execution of scope.think(); in testfire calls the function specified by the passed parameter "newmis".

Note that in the testfire function body with this method, you will not have access to the global entity "scope".

The curious may want to test this on their preferred qcc platform.

Edited by: numbersix

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.