Help for WHAM - All solved

Started by WHAM, Sun 18/03/2007 09:44:41

Previous topic - Next topic

WHAM

Im starting a game, and will probably need quite a bit of scripting help, so I'll make this one thread, and put my questions here as I come up with them.

My first problem is the following:

int tupu = 0;
if (tupu == 0) {Object[0].SetView(7);
tupu++;}
else if (tupu == 1) {Object[0].SetView(8);
tupu--;}

This script gives me an error "variable "[" is already defined." and I have no idea what this means. This script is meant to make a door open when a button is pressed, but if the door is already open, it closes the door.

I am inexperienced with this scripting, but if I'm correct this seems to be very similiar to Java code, with which I have some experience.

Any help, and patience, is truly appreciated.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GarageGothic

#1
There may be other problems, but for now it looks like a capitalization error. It should be object[0] not Object[0].

Edit: Does the code actually look like that, or is "int tupu" declared somewhere else, and you just put it there for this post? If this is the actual code, of course the first statement will always be true while the second will never run.

WHAM

#2
The int tupu; is in this code for now, and thats another problem. I've triedn putting it in global script, but it doesnt work. it just says "undefined symbol 'tupu' ".

EDIT: You were right, the problem was the capital "O":s, but I still cant seem to get the Tupu working.

As it is it is in the global script, and I get the error metioned above.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GarageGothic

#3
The other code is in the Room Script, I assume? Then also put "int tupu;" in the top of the room script.

However, I wonder if you need the int at all? Since you're switching between two object view, why not check for the current view instead?

Code: ags
if (object[0].View == 8) {
   object[0].SetView(7);
   }
else if (object[0].View == 7) {
   object[0].SetView(8);
   }


Edit: Are you animating the door at all (I don't see any object[0].Animate command)? If you're just switching between two sprites, one opened, one closed, it would be easier just to use object[0].Graphic to change it.

WHAM

Hahaha!

I realized my mistake: the original defining of "int tupu" was in the wrong place!

Thanks for the help, I think this will get me quite a bit further with my game.

If I need more help, I'll return to this thread in the future.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Khris

Here's an even shorter version:

Code: ags
object[0].SetView(15-object[0].View);

WHAM

Yeah, I'm back again!

This time I have a new problem going on. In my game's intro, I'm trying to get a character to move to the room's door, and to then go to the next room, but when the NPC wlks onto a region (any region, this one is supposed to change the characters lighting as he walks into the light).

How can I get the NPC to walk over these preset regions. The excact error I get says : "Error: Move character: Character not in current room."

I'm simply using the

"cAi1.Say("&3 Get going!");
cAi2.Say("&1 Yes sir!");
character[2].Walk (296, 140);"

script.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Ashen

Hmm, does the character actually START moving, or does it crash right away?
That error shouldn't have anything to do with Regions ... Obviously enough, it means you're trying to move a character that isn't in the current room. Is character[2] the right character to move?

What's the code for the Region (although, it should reall only be triggered by the player character walking over it)? Is it possible there's something else being triggered that changes the NPC's room, or tries to move another Character?

(Incidentally, to have Regions affect NPCs - for lighting effects, etc - check the NPC's coords against Region.GetAtRommXY in rep_ex. It's a little cumbersome, but it's the only way AFAIK.)
I know what you're thinking ... Don't think that.

WHAM

#8
FIXXED!!!

Figured out the problem myself.

Now for a simple question: How do I get the script to wait for the last one to have been completed before the next part starts?

Situation now: The NPC starts moving, and as soon as the NPC starts moving the door opens.

Wanted situation: The NPC starts moving, reaches his waypoint near the door, the door opens.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Ashen

So, what was the problem?

And for the new problem - how about adding the eBlock parameter to  Character.Walk?
I know what you're thinking ... Don't think that.

WHAM

The problem was mislocating the waypoint of the NPC, so that the NPC was trying to move through a blocking object. Moved waypoint, and had the door actually open so that the NPC wasnt trying to walk through the door, and works fine now.

And I had never heard of eblock before ^^. I've tried reading the tutorials, but I've never bumped into that.

Thanks a buch! Getting back to work!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Khris


WHAM

Ok, I'm back... again...

Does anybody have ideas on how to make this script:

character[0].StopMoving();
cAi1.Say("&1 Ok, lets get moving!"); 
cAi1.Say("&2 Ellie, I want you to check the containers!");
cAi1.Say("&3 Get going!");
cAi2.Say("&1 Yes sir!");
character[2].Walk (269, 140, eBlock);
object[0].SetView(3);
object[0].Animate(1, 3);
character[2].Walk (313,140);
cAi1.Say("&4 Mike, you have to check the engines.");
character[2].ChangeRoom(10);
object[0].SetView(4);
object[0].Animate(1, 3);
cAi1.Say("&5 You know where they are, so get moving!");
cAi1.Say("&6 I have to get to the command room, and send out the distress signal.");


To only run once in the game.

The script is run when the player steps into a region, but the second time the player steps into the region, the script is run again, and the game crashes because cAi2 is no longer in the room! I was thinking about making a variable that changes from zero into one the first time this is run, but if I put this variable into the room script, it gets defined into zero every time player enters the room!

I've thought about making a second room, otherwise the same than the first, but without this one region, but this seems a bit troublesome.

My guess is that you people have a simple solution here, but it just eludes me...
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Creator

just turn the region off  ;D :

Code: ags

character[0].StopMoving();
cAi1.Say("&1 Ok, lets get moving!");  
cAi1.Say("&2 Ellie, I want you to check the containers!");
cAi1.Say("&3 Get going!");
cAi2.Say("&1 Yes sir!");
character[2].Walk (269, 140, eBlock);
object[0].SetView(3);
object[0].Animate(1, 3);
character[2].Walk (313,140);
cAi1.Say("&4 Mike, you have to check the engines.");
character[2].ChangeRoom(10);
object[0].SetView(4);
object[0].Animate(1, 3);
cAi1.Say("&5 You know where they are, so get moving!");
cAi1.Say("&6 I have to get to the command room, and send out the distress signal.");
region[1].Enabled = false;

WHAM

Why did I just start feeling like a moron?...  ;D

Thanks!

But for the future, how can I make a variable that can be called upon any rooms scripts? Is it even possible? I tried setting a variable in the global script, but it couldn't be called upon inside the room. Should it work or was I just... wrong?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Creator

Code: ags

int cutscene;
if (cutscene == 0) {
character[0].StopMoving();
cAi1.Say("&1 Ok, lets get moving!");  
cAi1.Say("&2 Ellie, I want you to check the containers!");
cAi1.Say("&3 Get going!");
cAi2.Say("&1 Yes sir!");
character[2].Walk (269, 140, eBlock);
object[0].SetView(3);
object[0].Animate(1, 3);
character[2].Walk (313,140);
cAi1.Say("&4 Mike, you have to check the engines.");
character[2].ChangeRoom(10);
object[0].SetView(4);
object[0].Animate(1, 3);
cAi1.Say("&5 You know where they are, so get moving!");
cAi1.Say("&6 I have to get to the command room, and send out the distress signal.");
cutscene++;
}

if you want to make the variable go down:
Code: ags

if (cutscene > 0) { //you put this after your scene natrually
cutscene--;
}

WHAM

But doesn't this cause the int cutscene to always be zero when read, as it is defined at the start of the script? This is excactly my problem.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Creator

#17
Didn't you notice the cutscene++; at the end, but if that doesn't work (because i have kind of the same problem) you could try cutscene+=1; (which probebly wouldn't work anyway) or you could use a GlobalInt eg:

Code: ags

if (GetGlobalInt(1) == 0) {
character[0].StopMoving();
cAi1.Say("&1 Ok, lets get moving!");  
cAi1.Say("&2 Ellie, I want you to check the containers!");
cAi1.Say("&3 Get going!");
cAi2.Say("&1 Yes sir!");
character[2].Walk (269, 140, eBlock);
object[0].SetView(3);
object[0].Animate(1, 3);
character[2].Walk (313,140);
cAi1.Say("&4 Mike, you have to check the engines.");
character[2].ChangeRoom(10);
object[0].SetView(4);
object[0].Animate(1, 3);
cAi1.Say("&5 You know where they are, so get moving!");
cAi1.Say("&6 I have to get to the command room, and send out the distress signal.");
SetGlobalInt(1, 1);
}

if you want to make the variable go down:
Code: ags

SetGlobalInt(1, 0);


also making the variable go down is optional, that's just there incase you want it to go down.
(and no, I don't think variables can be called from the global script, I came accross something in the manuel, but it looked REALLY complicated)

WHAM

if (GetGlobalInt(1) == 0) {
character[0].StopMoving();
cAi1.Say("&1 Ok, lets get moving!");
cAi1.Say("&2 Ellie, I want you to check the containers!");
cAi1.Say("&3 Get going!");
cAi2.Say("&1 Yes sir!");
character[2].Walk (269, 140, eBlock);
object[0].SetView(3);
object[0].Animate(1, 3);
character[2].Walk (313,140);
cAi1.Say("&4 Mike, you have to check the engines.");
character[2].ChangeRoom(10);
object[0].SetView(4);
object[0].Animate(1, 3);
cAi1.Say("&5 You know where they are, so get moving!");
cAi1.Say("&6 I have to get to the command room, and send out the distress signal.");
SetGlobalInt(1, 1);
}


Ok, this code works as it is, but where does it set the variable, as in CREATES the variable?

Does this happen automativcally at GetGlobalInt(1)?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Ashen

The GlobalInts (Get/SetGlobalInt are 500 ints hardcoded into AGS. You don't have to create them yourself, they just exist and can be used, well, globally. This is all explained  IN THE MANUAL. Please, read it before postng posting other questions (like the eBlock one) that are answered in there.

Quote
But for the future, how can I make a variable that can be called upon any rooms scripts? Is it even possible?
Quote
(and no, I don't think variables can be called from the global script, I came accross something in the manuel, but it looked REALLY complicated)

Variables declared in Room scripts can't be made Global. Variables declared in the Global script  can. It's described (in detail) in the BFAQ (the manual version isn't quite as clear, it's true). Again, take a read through the BFAQ, see if it answers your questions before you have to ask them.

Quote
But doesn't this cause the int cutscene to always be zero when read, as it is defined at the start of the script? This is excactly my problem.
Quote
Didn't you notice the cutscene++; at the end, but if that doesn't work (because i have kind of the same problem) you could try cutscene+=1; (which probebly wouldn't work anyway)

No, WHAM is right - ints are set to 0 at declaration unless you say otherwise, so while cutscene ++; will set it to 1, it'll be 'destroyed' when the interaction finishes and re-declared as 0 next time the player steps onto the Region. Placing the declaration (int cutscene;) at the top of the room script (or just anywhere before you need to use it, provided it's outside of any functions) should work for cases like this, where it only has to affect things in the one room.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk