Author |
Topic: level.onTimeLimit results in "self" becoming undefined |
mortifer |
General Member Since: Jul 19, 2015 Posts: 19 Last: Jul 6, 2016 [view latest posts] |
|
|
|
DeekCiti |
|
General Member Since: Mar 13, 2008 Posts: 1293 Last: Jul 9, 2016 [view latest posts] |
|
|
|
mortifer |
General Member Since: Jul 19, 2015 Posts: 19 Last: Jul 6, 2016 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Monday, Jun. 6, 2016 03:42 pm |
|
I mean, literally just that 1 line of code in that function.
Code: onTimeLimit() {
self iprintlnbold("time limit reached");
}
ANY single line that refers to the self entity will error claiming that self is not an entity.
edited on Jun. 6, 2016 08:43 am by mortifer |
|
|
|
.KiLL3R. |
|
General Member Since: Oct 26, 2006 Posts: 1437 Last: Jul 3, 2017 [view latest posts] |
|
|
|
mortifer |
General Member Since: Jul 19, 2015 Posts: 19 Last: Jul 6, 2016 [view latest posts] |
|
|
|
.KiLL3R. |
|
General Member Since: Oct 26, 2006 Posts: 1437 Last: Jul 3, 2017 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Tuesday, Jun. 7, 2016 12:11 am |
|
What are you expecting 'self' to be?
Somewhere in _globallogic.gsc or the gametype .gsc there should be a line that looks something like this:
Code:
[[level.onTimeLimit]]();
'self' will be undefined in the onTimeLimit() function since it was not called on anything. If you want to print something to all players then just do:
Code:
onTimeLimit() {
iprintlnbold("time limit reached");
}
If iPrintln or iPrintlnBold is not called on anything then it will print to all players.
Here's an example where 'self' will be defined:
Code:
bleh()
{
players = getentarray("player", "classname");
for(i=0;i<players.size;i++)
players[i] doStuff(); // doStuff() was called on players[i], which is a player
}
doStuff()
{
self suicide(); // self is the player
}
|
|
|
|
.KiLL3R. |
|
General Member Since: Oct 26, 2006 Posts: 1437 Last: Jul 3, 2017 [view latest posts] |
|
|
|
mortifer |
General Member Since: Jul 19, 2015 Posts: 19 Last: Jul 6, 2016 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Tuesday, Jun. 7, 2016 12:50 am |
|
I love replying and then finding out the forums page had an error and failed to post my long reply! ;)
All I have done is taken the dm.gsc from my custom pml220 mod. In it it makes all the callbacks from globallogic.
Code: maps\mp\gametypes\_globallogic::init();
maps\mp\gametypes\_callbacksetup::SetupCallbacks();
maps\mp\gametypes\_globallogic::SetupCallbacks();
level.onStartGameType = ::onStartGameType;
level.onSpawnPlayer = ::onSpawnPlayer;
level.onPlayerKilled = ::onPlayerKilled;
level.onTimeLimit = ::onTimeLimit;
level.onScoreLimit = ::onScoreLimit;
level.onEndGame = ::onEndGame;
Code: onTimeLimit() {
// remove the line below and the script works perfectly
self iprintlnbold("time limit reached"); // error claiming "self" is not an entity<br />
<br />
winner = undefined;
if (level.teamBased) {
if (game["teamScores"]["allies"] == game["teamScores"]["axis"]) winner = "tie";
else if (game["teamScores"]["axis"] > game["teamScores"]["allies"]) winner = "axis";
else winner = "allies";
} else winner = maps\mp\gametypes\_globallogic::getHighestScoringPlayer();
makeDvarServerInfo("ui_text_endreason", game["strings"]["time_limit_reached"]);
setDvar("ui_text_endreason", game["strings"]["time_limit_reached"]);
thread maps\mp\gametypes\_globallogic::endGame(winner, game["strings"]["time_limit_reached"]);
}
I came across this because at the top of onTimeLimit() I added a final call for a custom killcam script I made. It works 100% except for when attempting to call it at the top of onTimeLimit(). If I put it back there, it errors on the first line referencing "self" claiming same as the iprintlnbold().
edited on Jun. 6, 2016 05:51 pm by mortifer
edited on Jun. 6, 2016 05:51 pm by mortifer |
|
|
|
FzBr.d4rk |
|
General Member Since: Jan 23, 2011 Posts: 86 Last: Jun 7, 2016 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Tuesday, Jun. 7, 2016 07:51 am |
|
Simply remove "self" in the beginning and it should work.
Code:
onTimeLimit()
{
iprintlnbold("time limit reached");
// code
}
|
|
|
|
mortifer |
General Member Since: Jul 19, 2015 Posts: 19 Last: Jul 6, 2016 [view latest posts] |
|
|
|