Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds
Watch MODSonair

Members Online

»
0 Active | 55 Guests
Online:

LATEST FORUM THREADS

»
Cod2 New Zombie Mod
CoD2 Map + Mod Releases
AI way
CoD Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Restricted Access
Page
Previous Page
subscribe
Author Topic: level.onTimeLimit results in "self" becoming undefined
.KiLL3R.
General Member
Since: Oct 26, 2006
Posts: 1437
Last: Jul 3, 2017
[view latest posts]
Level 8
Category: CoD4 Scripting
Posted: Tuesday, Jun. 7, 2016 04:46 pm
Storing stuff in 'level' is perfectly fine.

'Self' was never allocated to begin with, since onTimeLimit was not called on anything! I'm still not sure what object or entity you're expecting 'self' to be.
Share |
mortifer
General Member
Since: Jul 19, 2015
Posts: 19
Last: Jul 6, 2016
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Tuesday, Jun. 7, 2016 04:52 pm
It had to be allocated since promod's dm.gsc references it as well as my script works 100% when calling the final killcam in the same method evoked at the playerKilled event. All references being self there.

I've debugged it for several days and self is fully existent up until the timer is up. Self even stays if the match is point based. So it is something with the match timer itself that trashes self.
Share |
.KiLL3R.
General Member
Since: Oct 26, 2006
Posts: 1437
Last: Jul 3, 2017
[view latest posts]
Level 8
Category: CoD4 Scripting
Posted: Tuesday, Jun. 7, 2016 05:23 pm
'Self' is a special local variable. It differs depending on the how the function was called. 'Self' will be the object or entity that the function was called on.

Since onTimeLimit was not called on anything, 'self' will be undefined (actually I think it uses the 'self' from the function it was called from, which would be 'level' from the checkTimeLimit() function and 'level' is not an entity).

playerKilled is called from _callbacksetup::CodeCallback_PlayerKilled(), where 'self' is defined as the player. So the 'self' in playerKilled is the player who died. 'Self' will change depending on which player died.

Here's some code to show that 'self' in the doStuff() function can be 2 different things, a script_model and a player:

Code:

blah()
{
	model = spawn("script_model", (0,0,0));
	model doStuff(); // 'self' will be the model

	players = getentarray("player", "classname");
	players[0] doStuff(); // 'self' will be a player
}

doStuff()
{
	self setModel("knife");
	iPrintlnBold("I am a " + self.classname);
}


When the function ends the variable 'self' will no longer exist.

Everything you are experiencing is correct and expected based on how you've coded it.
Share |
mortifer
General Member
Since: Jul 19, 2015
Posts: 19
Last: Jul 6, 2016
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Tuesday, Jun. 7, 2016 05:29 pm
I too overwrote the player killed method and have my own residing in my modified dm.gsc. The self that it references is in my dm.gsc not globallogic.
Share |
.KiLL3R.
General Member
Since: Oct 26, 2006
Posts: 1437
Last: Jul 3, 2017
[view latest posts]
Level 8
Category: CoD4 Scripting
Posted: Tuesday, Jun. 7, 2016 05:34 pm
Same idea still applies, 'self' is local and will change depending on who died.

'level' is a global variable, using 'level' in any function will access the same object.
'self' is a local variable, it can be different each time a function is called, even if it's the same function being called or a different function.
Share |
Restricted Access Restricted Access
Page
Previous Page
subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»