SolvedUnknown function (Really short code)

Posts 110 of 10 · Page 1 of 1
Unknown function (Really short code)
Hey guys. This is, I think my first port here, so... Hi.

I am new to GSC (Just started learning two days ago) and don't have much previous experience with programming (little bit of vb.net). So I'm teaching myself by doing small things, like toggles using examples from bits of code I find online.

Today I ran into my first problem I can't seem to solve and would love if somebody could help me out. I will attach only the code I have modified, however I think the problem exists in doTestToggleTwo().

Code:
onPlayerSpawned()
{
	self endon("disconnect");
	
	for(;;)
	{
		self waittill("spawned_player"); //Waits for player spawn
		self iPrintlnBold( "^3Hello World" ); //Mod name
		wait 1.5;
		self iPrintln( "^1MD6 ^7version ^11r1826" ); //Mod version
		wait 1.5;
		self iPrintln( "Instilizing ^3doSplash() ^1&& ^3doTestToggle ^1&& ^3doTestToggle2" ); //Notification
		self.testvar=0; //Sets testvar to 0 for toggle
		self thread doSplash(); //Instilizes doSplash()
		self thread doTestToggle(); //Instilizes doTestToggle
		self thread doTestToggleTwo(); //Instilizes doTestToggle2
		wait 1.5;
		self iPrintln( "Instilized" ); //Notification
	}
}


doSplash()
{
	self endon("disconnect");
	self endon("death");
	
	wait 1;	
		notifyData = spawnstruct();
		notifyData.iconName = "rank_prestige10"; //Icon, 10th prestige
		notifyData.titleText = "^5GSC ^7by ^2uPayme^0iFixit"; //Line 1
		notifyData.notifyText = "^3Hello World"; //Line 2
		notifyData.notifyText2 = "Press ^1actionslot2 ^7for mods"; //Line 3
		notifyData.glowColor = (2.55, 0.0, 0.0); //RGB Color array divided by 100
		notifyData.sound = "veh_ac130_sonic_boom"; //Sound, level up sound here
		self thread maps\mp\gametypes\_hud_message::notifyMessage( notifyData );
}


doTestToggle()
{
self endon("disconnect");
self endon("death");
	
self notifyOnPlayerCommand("1", "+actionslot 2"); //Aparantly this is needed when using button press
for(;;){ //for(;;) allows a loop
	self waittill("1"); //Waits for actionslot 2 to be pressed
	if (self.testvar==0) //Begin my favorite toggle logic :D
		{
		self.testvar=1;
		self iPrintLnBold("^3doTestToggle() ^6DVARS ^7set to ^1!= ^7standard");
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();
		}
	else
		{
		self.testvar=0;
		self iPrintLnBold("^3doTestToggle() ^6DVARS ^7set to ^1==");
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
		}
	}
}


doTestToggleTwo()
{
selfnotifyOnPlayerCommand("2", "+actionslot 1");
for(;;){
	self waittill("2");
	self.testvartwo+=1;
	switch(self.testvartwo)
		{
		case 1:
			self iPrintlnBold( self.testvartwo );
			break;
		case 2:
			self iPrintlnBold( self.testvartwo );
			break;
		case 3:
			self iPrintlnBold( self.testvartwo );
			break;
		default:
			self iPrintlnBold( self.testvartwo );
			self.testvartwo=0;
			break;
		}
	}
}
for now:

Code:
doTestToggle()
{
self endon("disconnect");
self endon("death");
	
self.testvar=0;

self notifyOnPlayerCommand("1", "+actionslot 2"); //Aparantly this is needed when using button press
for(;;){ //for(;;) allows a loop
	self waittill("1"); //Waits for actionslot 2 to be pressed
	if (self.testvar==0) //Begin my favorite toggle logic :D
		{
		self.testvar=1;
		self iPrintLnBold("^3doTestToggle() ^6DVARS ^7set to ^1!= ^7standard");
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();
		}
	else
		{
		self.testvar=0;
		self iPrintLnBold("^3doTestToggle() ^6DVARS ^7set to ^1==");
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
		}
	}
}
Quote Originally Posted by Jorndel View Post
for now:
code
Okay, wasn't sure if that would be reset every time I toggled it if I put that there, so I put it in the onPlayerSpawn()

Didn't fix it though.
Quote Originally Posted by uPaymeiFixit View Post
Okay, wasn't sure if that would be reset every time I toggled it if I put that there, so I put it in the onPlayerSpawn()

Didn't fix it though.
Thats because it have to be in the same thread as you use the function it...

You have to give it an value before you change the value.


It dosn't exsist....

so you have to tell the mod what the (forgot what it was..) is before changing it....
Code:
onPlayerSpawned()
{
	self endon("disconnect");
	
	for(;;)
	{
		self waittill("spawned_player"); //Waits for player spawn
		self iPrintlnBold( "^3Hello World" ); //Mod name
		wait 1.5;
		self iPrintln( "^1MD6 ^7version ^11r1826" ); //Mod version
		wait 1.5;
		self iPrintln( "Instilizing ^3doSplash() ^1& ^3doTestToggle ^1& ^3doTestToggle2" ); //Notification
		self.testvar = 0; //Sets testvar to 0 for toggle
		self thread doSplash(); //Instilizes doSplash()
		self thread doTestToggle(); //Instilizes doTestToggle
		self thread doTestToggleTwo(); //Instilizes doTestToggle2
		wait 1.5;
		self iPrintln( "Instilized" ); //Notification
	}
}


doSplash()
{
	self endon("disconnect");
	self endon("death");
	
	wait 1;	
		notifyData = spawnstruct();
		notifyData.iconName = "rank_prestige10"; //Icon, 10th prestige
		notifyData.titleText = "^5GSC ^7by ^2uPayme^0iFixit"; //Line 1
		notifyData.notifyText = "^3Hello World"; //Line 2
		notifyData.notifyText2 = "Press ^1actionslot2 ^7for mods"; //Line 3
		notifyData.glowColor = (2.55, 0.0, 0.0); //RGB Color array divided by 100
		notifyData.sound = "veh_ac130_sonic_boom"; //Sound, level up sound here
		self thread maps\mp\gametypes\_hud_message::notifyMessage( notifyData );
}


doTestToggle()
{
self endon("disconnect");
self endon("death");
	
self notifyOnPlayerCommand("1", "+actionslot 2"); //Aparantly this is needed when using button press
for(;;){ //for(;;) allows a loop
	self waittill("1"); //Waits for actionslot 2 to be pressed
	if(self.testvar == 0 ) //Begin my favorite toggle logic :D
		{
		self.testvar = 1;
		self iPrintLnBold("^3doTestToggle ^6DVARS ^7set to ^1=7standard"); //Wow, this is so messy fix it up...
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();
		}
	else
		{
		self.testvar = 0; //Why would you need this? It's already set
		self iPrintLnBold("^3doTestToggle() ^6DVARS ^7set to ^1==");
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
		}
	}
}


doTestToggleTwo()
{
selfnotifyOnPlayerCommand("2", "+actionslot 1");
for(;;){
	self waittill("2");
	self.testvartwo += 1;

	switch(self.testvartwo)
		{
		case 1:
			self iPrintlnBold( self.testvartwo );
			break;
		case 2:
			self iPrintlnBold( self.testvartwo );
			break;
		case 3:
			self iPrintlnBold( self.testvartwo );
			break;
		default:
			self iPrintlnBold( self.testvartwo );
			self.testvartwo = 0;
			break;
		}
	}
}
Just found syntax errors (and a bit messy scripting, but that part is up to you ), no unknown function...

Oh, "default" dosen't exist...

Edit: Yay, 500 posts :P
Quote Originally Posted by EpicPlayer View Post
Code:
...
self.testvar = 0; //Why would you need this? It's already set
...
Just found syntax errors (and a bit messy scripting, but that part is up to you ), no unknown function...

Oh, "default" dosen't exist...

Edit: Yay, 500 posts :P
The self.testvar = 0; is needed so that when you press actionslot2 and testvar = 1 it will go back to 0. Is there a better way to do it?

Sorry about the messy code. Like I said, I'm very new at this. As for the syntax errors, everything you changed worked before (doTestToggle worked like it was)

I changed the default to case 4:, but I thought default did exist. I found it on this guide (last example)

Congrats on the 500. I'm on 3



Here is my revised code. I figured out it is in doTestToggleTwo (I removed it and it worked) Still get unknown function with this:
Code:
onPlayerSpawned()
{
	self endon("disconnect");
	
	for(;;)
	{
		self waittill("spawned_player"); //Waits for player spawn
		self thread doSplash(); //Instilizes doSplash()
		self thread doTestToggle(); //Instilizes doTestToggle
		self thread doTestToggleTwo(); //Instilizes doTestToggle2
	}
}


doSplash()
{
	self endon("disconnect");
	self endon("death");
	
	self iPrintlnBold( "^3Hello World" ); //Mod name
	self iPrintln( "^1MD1 ^7version ^11r2103" ); //Mod version
	
	wait 2.5;
	
	notifyData = spawnstruct();
		notifyData.iconName = "rank_prestige10"; //Icon, 10th prestige
		notifyData.titleText = "^5GSC ^7by ^2uPayme^0iFixit"; //Line 1
		notifyData.notifyText = "^3Hello World"; //Line 2
		notifyData.notifyText2 = "Press ^1actionslot2 ^7for mods"; //Line 3
		notifyData.glowColor = (2.55, 0.0, 0.0); //RGB Color array divided by 100
		notifyData.sound = "veh_ac130_sonic_boom"; //Sound, level up sound here
		self thread maps\mp\gametypes\_hud_message::notifyMessage( notifyData );
}


doTestToggle()
{
self endon("disconnect");
self endon("death");
	
self.testvar = 0; //Sets testvar to 0 when you die
self notifyOnPlayerCommand("1", "+actionslot 2"); //Aparantly this is needed when using button press

for(;;){ //for(;;) allows a loop
	self waittill("1"); //Waits for actionslot 2 to be pressed
	if(self.testvar == 0 )
		{
		self.testvar = 1;
		self iPrintLnBold("testvar = " && self.testvar);
		
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();
		}
	else
		{
		self.testvar = 0; 
		self iPrintLnBold("testvar = " && self.testvar);
		
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
		}
	}
}


doTestToggleTwo()
{
self endon("disconnect");
self endon("death");

self.testvartwo = 0; //Sets testvartwo to 0 when you die
selfnotifyOnPlayerCommand("2", "+actionslot 1");

for(;;){
	self waittill("2");
	self.testvartwo += 1; //Should add up testvartwo every time actionslot1 is pressed

	switch(self.testvartwo)
		{
		case 1:
			self iPrintlnBold( self.testvartwo );
			break;
		case 2:
			self iPrintlnBold( self.testvartwo );
			break;
		case 3:
			self iPrintlnBold( self.testvartwo );
			break;
		case 4:
			self iPrintlnBold( self.testvartwo );
			self.testvartwo = 0; //Sets testvartwo back to 0 to create a "loop"
			break;
		}
	}
}
Quote Originally Posted by uPaymeiFixit View Post
The self.testvar = 0; is needed so that when you press actionslot2 and testvar = 1 it will go back to 0. Is there a better way to do it?

Sorry about the messy code. Like I said, I'm very new at this. As for the syntax errors, everything you changed worked before (doTestToggle worked like it was)

I changed the default to case 4:, but I thought default did exist. I found it on this guide (last example)

Congrats on the 500. I'm on 3



Here is my revised code. I figured out it is in doTestToggleTwo (I removed it and it worked) Still get unknown function with this:
Code:
onPlayerSpawned()
{
	self endon("disconnect");
	
	for(;;)
	{
		self waittill("spawned_player"); //Waits for player spawn
		self thread doSplash(); //Instilizes doSplash()
		self thread doTestToggle(); //Instilizes doTestToggle
		self thread doTestToggleTwo(); //Instilizes doTestToggle2
	}
}


doSplash()
{
	self endon("disconnect");
	self endon("death");
	
	self iPrintlnBold( "^3Hello World" ); //Mod name
	self iPrintln( "^1MD1 ^7version ^11r2103" ); //Mod version
	
	wait 2.5;
	
	notifyData = spawnstruct();
		notifyData.iconName = "rank_prestige10"; //Icon, 10th prestige
		notifyData.titleText = "^5GSC ^7by ^2uPayme^0iFixit"; //Line 1
		notifyData.notifyText = "^3Hello World"; //Line 2
		notifyData.notifyText2 = "Press ^1actionslot2 ^7for mods"; //Line 3
		notifyData.glowColor = (2.55, 0.0, 0.0); //RGB Color array divided by 100
		notifyData.sound = "veh_ac130_sonic_boom"; //Sound, level up sound here
		self thread maps\mp\gametypes\_hud_message::notifyMessage( notifyData );
}


doTestToggle()
{
self endon("disconnect");
self endon("death");
	
self.testvar = 0; //Sets testvar to 0 when you die
self notifyOnPlayerCommand("1", "+actionslot 2"); //Aparantly this is needed when using button press

for(;;){ //for(;;) allows a loop
	self waittill("1"); //Waits for actionslot 2 to be pressed
	if(self.testvar == 0 )
		{
		self.testvar = 1;
		self iPrintLnBold("testvar = " && self.testvar);
		
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();
		}
	else
		{
		self.testvar = 0; 
		self iPrintLnBold("testvar = " && self.testvar);
		
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
		}
	}
}


doTestToggleTwo()
{
self endon("disconnect");
self endon("death");

self.testvartwo = 0; //Sets testvartwo to 0 when you die
selfnotifyOnPlayerCommand("2", "+actionslot 1");

for(;;){
	self waittill("2");
	self.testvartwo += 1; //Should add up testvartwo every time actionslot1 is pressed

	switch(self.testvartwo)
		{
		case 1:
			self iPrintlnBold( self.testvartwo );
			break;
		case 2:
			self iPrintlnBold( self.testvartwo );
			break;
		case 3:
			self iPrintlnBold( self.testvartwo );
			break;
		case 4:
			self iPrintlnBold( self.testvartwo );
			self.testvartwo = 0; //Sets testvartwo back to 0 to create a "loop"
			break;
		}
	}
}
Yes an much better way...
Code:
doTestToggle()
{
self endon("disconnect");
self endon("death");
	
for(;;)
{
		self notifyOnPlayerCommand("trigger", "+actionslot 2");

		self waittill("trigger");
		self iPrintLnBold("^3Night Vision 2ON ^5& ^3Hide ^2ON");
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();

		self waittill("trigger");
		self iPrintLnBold("^3Night Vision 1OFF ^5& 3Hide ^2OFF");
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
}
}
Quote Originally Posted by Jorndel View Post
Yes a much better way...
Code:
doTestToggle()
{
self endon("disconnect");
self endon("death");
	
for(;;)
{
		self notifyOnPlayerCommand("trigger", "+actionslot 2");

		self waittill("trigger");
		self iPrintLnBold("^3Night Vision 2ON ^5& ^3Hide ^2ON");
		self VisionSetNakedForPlayer("cheat_chaplinnight", 1);
		self hide();

		self waittill("trigger");
		self iPrintLnBold("^3Night Vision 1OFF ^5& 3Hide ^2OFF");
		self VisionSetNakedForPlayer( getDvar("mapname"), 1);
		self show();
}
}
Awesome, I'll experiment with "trigger" later.

Thanks for the help guys, I figured it out. Took it apart one line at a time and found a really stupid error: "selfnotifyOnPlayerCommand("2", "+actionslot 1");" needs to be "self notifyOnPlayerCommand("2", "+actionslot 1");"
/solved
/closed
Posts 110 of 10 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?