Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Kyka

Season 1 Episode 4. "Kyka's nublet ACS questions"

Recommended Posts

Ok.

Here is what I want to do. There is a yellow key switch. If you have no yellow key, I want it to print the message "You need a yellow key." and then repeated pressings of the switch do nothing.

Then when you get a yellow key and hit the switch, a door is opened and a message is printed that says "A nearby door is opened". and then repeated pressings of this switch again do nothing.

I have tried lots of things, and this is where the script is at presently. (Once again, forgive the abomination of coding that this is. I am sure that if I showed all my earlier attempts, I would give real coders nightmares.)
On the bright side, I have managed to make all my other scripts work so far (Not that they are massively complicated or anything.)

Anyway, here is the code. I kind of see why it is all retarded, but I can't get my brain to think like a programmer. Any help with making this work, and/or an explanation of why this doesn't work would be much appreciated.

thanks guys. :)

#include "zcommon.acs"


int yellowkey = 0;
int noyellowkey = 0;


Script 8 (void) //secret yellow key switch
	{
	While (noyellowkey == 0)
		{
		noyellowkey++;
		print(s:"You need a yellow card to activate this switch.");
		delay(35);
		
		}
	While (CheckInventory("YellowCard") && (yellowkey == 0))
		{
		yellowkey++;
		Door_Open(44, 64);
		print(s:"A door is opened nearby.");
		delay(35);
		}
	While (yellowkey == 1);
		{
		delay(35*60);
		}
	While (noyellowkey == 1);
		{
		delay(35*60);
		}
}

Share this post


Link to post

Kyka said:

#include "zcommon.acs"


int yellowkey = 0;
int noyellowkey = 0;


Script 8 (void) //secret yellow key switch
	{
	While (noyellowkey == 0)
		{
		noyellowkey++;
		print(s:"You need a yellow card to activate this switch.");
		delay(35);
		
		}
	While (CheckInventory("YellowCard") && (yellowkey == 0))
		{
		yellowkey++;
		Door_Open(44, 64);
		print(s:"A door is opened nearby.");
		delay(35);
		}
	While (yellowkey == 1);
		{
		delay(35*60);
		}
	While (noyellowkey == 1);
		{
		delay(35*60);
		}
}


Lets take a quick look at this code and what it does, first:

While (noyellowkey == 0)
{
	noyellowkey++;
	print(s:"You need a yellow card to activate this switch.");
	delay(35);		
}]
"While" might be easier to understand as "as long as." It goes on and on forever until the condition given becomes false. Here your condition is that 'noyellowkey' is zero...but inside the While-block you right away make it non-zero. Thus, this can never loop, in which case do not use While here. Use If instead. Yes, the functionality will stay the same, but when anyone else reads "While", they think "Loop" and when they read "If" they think "Condition."
While (yellowkey == 1);
{
	delay(35*60);
}
While (noyellowkey == 1);
{
	delay(35*60);
}
Notice that your script always reaches these two block, and that unless you change 'yellowkey' and 'noyellowkey' somewhere else, they will always be 1 (you define them as 0 and make them 1 inside the first whiles). Because they are always 1, what these two Whiles mean is that this script will always loop forever...without ever terminating, and never doing anything at all except delaying itself and checking if 'yellowkey' or 'noyellowkey' has become something else than 1.

This is, simply put, wrong. When you use the switch it creates a new instance of this script. You could have one billion Script 8s running at the same time if you just bothered using your switch that often, because the script never terminates.



As for the code:
#include "zcommon.acs"

int yellow_switch_used_without_key = 0;
int yellow_switch_used_with_key = 0;

Script 8 (void) //secret yellow key switch
	{
	if(yellow_switch_used_without_key == 0 && !CheckInventory("YellowCard")){
		//The exclamation mark in the if-statement inverts the statement.
		//In other words, it returns true if "CheckInventory()" return false.

		yellow_switch_used_without_key = 1;
		print(s:"You need a yellow card to activate this switch.");
	}else if(yellow_switch_used_with_key == 0 && CheckInventory("YellowCard")){
		//Note that I'm not using the exclamation mark here, so this will
		//be true only when you actually have the yellow key

		yellow_switch_used_with_key = 1;
		Door_Open(44, 64);
		print(s:"A door is opened nearby.");
	}
}

Share this post


Link to post

Heh. I knew my script was looping over and over and doing all sorts of ugly crap, but I figured "as long as it works, I'll live". Course I couldn't even make it work, so duuuh to me.

I spent ages (well like a half an hour anyway) trying to find out how to make a statement that checked to see that you didn't have the yellow key, but it is simple as putting a '!' there. I really don't even know basics like this. BUt I am getting there.

Thanks so much Jodwin for explaining this. I get it much better now. Your coding here is elegant and simple, as opposed to my "monkey throw shit at wall and something will stick" approach to coding. And thanks ArmouredBlood also. I appreciate your guest appearance on this episode of "Kyka's nublet ACS questions" Jodwin, of course, got the star role.

As it turns out, this script was the last thing I needed to finish the entire level for my project I working on, so now that is out of the way, it is down to some serious Claus2 testing.

:S

Share this post


Link to post
Kyka said:

And thanks ArmouredBlood also. I appreciate your guest appearance on this episode of "Kyka's nublet ACS questions" Jodwin, of course, got the star role.

Heh, 'best supporting actor' award here I come x)

As it turns out, this script was the last thing I needed to finish the entire level for my project I working on, so now that is out of the way, it is down to some serious Claus2 testing.

:S


Yay, kyka map released soon :) or ... is it an ep? ooooooooh

Share this post


Link to post
Kyka said:

I spent ages (well like a half an hour anyway) trying to find out how to make a statement that checked to see that you didn't have the yellow key, but it is simple as putting a '!' there. I really don't even know basics like this. BUt I am getting there.

Just to make things more clear (or to make them more confusing :P), these would all have the same result with the given a value:

int a = 1;

if(a != 1){ //'If a equals anything but 1', or 'If a DOES NOT equal 1'
    ...
}

if(a == 0){ //'If a equals 0'
    ...
}

if(!a){ //'If a is false' - AFAIK in ACS the numerical value 0 is false, so since a = 1, a is true
    ...
}

if(a == false){ //See above! The last three statements are actually exactly the same!
    ...
}
You could replace 'a' with pretty much anything - including the CheckInventory()-function.

Now take a look this, when would this if-statement be true?
if(!(yellow_switch_used_without_key == 0 && !CheckInventory("YellowCard"))){
    ...
}
Spoiler

It's true whenever you either:
1) Have the yellow key or
2) Have already used the switch

Share this post


Link to post

For that statement, doesn't && mean that they both must be true, not one or the other?

Other than that, I got the right answer. Thanks Jodwin.



And AB. This is probably a long term project. If everything works out well, I will have the first episode done near the end of the year tho. If you are interested, there will be some playtesting needed before that. Thanks for the interest bro. :D

Share this post


Link to post
Kyka said:

And AB. This is probably a long term project. If everything works out well, I will have the first episode done near the end of the year tho. If you are interested, there will be some playtesting needed before that. Thanks for the interest bro. :D


Cool, single maps always seem limited, even the big hour+ ones. I hope you're pacing yourself though, it'd suck to be halfway done and run out of ideas for a year then scrap half the stuff you did map >.<

Whenever you need some playtesting just message me, I've got plenty of free time for now (me = jobless college student who registered late for classes).

Share this post


Link to post

Does this 'scripting language' have a name? Its apparently not c++, but the while's and if's etc make it seem logically similar.. why use this scripting language instead of c++? Did id software make this scripting language, or the maker of zdoom or something? (it only works with zdoom?)

Share this post


Link to post

The ability to script and all these extra features were Hexen additions originally, I thought. Don't know a lot about it, heh, having a hard enough time simply making it work.

Share this post


Link to post
gggmork said:

Does this 'scripting language' have a name? Its apparently not c++, but the while's and if's etc make it seem logically similar.. why use this scripting language instead of c++? Did id software make this scripting language, or the maker of zdoom or something? (it only works with zdoom?)

It's ACS, and it was originally made for Hexen. Yeah, it shares a lot of syntax similarities with C.

Kyka said:

For that statement, doesn't && mean that they both must be true, not one or the other?

Well, let me cut it to pieces:

if(  !(  yellow_switch_used_without_key == 0 && !CheckInventory("YellowCard")  )  ){
    ...
}
There are a few separate statements in there:
yellow_switch_used_without_key == 0 //This should be obvious
!CheckInventory("YellowCard") //This should be obvious too


//Yes, you are right, this is true only when both of the statements are true:
(yellow_switch_used_without_key == 0 && !CheckInventory("YellowCard")) 


//However! Now that I add the exclamation mark, whenever the statement inside the brackets is false, the whole thing becomes true
!(yellow_switch_used_without_key == 0 && !CheckInventory("YellowCard"))
//Which means, that for the whole thing to be true, actually either one or both of the statements inside the brackets has to be false.
//It doesn't matter which one is false, or how many of them are false.
If you want to read more about the logic behind these statements, check up on Boolean logic

Share this post


Link to post

I know the basic concepts of boolean logic, but not much more than that.
I had to read through the last post a few times before I really got it, but now I understand what is going on there.

Thanks again Jodwin. This has been so helpful.

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
×