non walkable area and integers

Started by ManicMatt, Wed 11/01/2006 14:26:37

Previous topic - Next topic

ManicMatt

Sorry but I didn't really know what to call my problem!

Take a look at this picture:



My EGO can interact with the skip, and climb onto it (and now he's stuck on a non-walkable area until he interacts with the skip again and thus climbs back down again). However I now have the problem of him still being able to interact with everything else in the room. He'll just stand there stuck and pick up things in the room as if by magic.

I've already done EVERYTHING in the scene, all the interactions etc.

One idea I had was to make my character change rooms, by showing a room that's just a picture of the EGO up close or something, and then taking him back to the room and now he is back on the ground again. This would work, but break up the flow of the game and look a bit crap I think.

I think integers if/else and all that might work, but looking at the tutorials Ashen posted recently I don't understand how to do it.

Unless someone is able to explain it better (A guide for beginner's my ass!Ã,  :P ) or please offer an alternative method, I'll have to go with the room jumping idea.

Thanks!

DoorKnobHandle

#1
Yes, you can use variables to do this.

Just add a boolean variable to the room script file:

Code: ags

bool PlayerIsOnSkip;


When the player enters the screen: set it to "false", so that it actually starts with a "false" value (because the player starts not being on the skip of course):

Code: ags

PlayerIsOnSkip = false;


Now, whenever the player is climbing up the skip, set it to "true":

Code: ags

PlayerIsOnSkip = true;


And whenever he leaves it, set it to "false":

Code: ags

PlayerIsOnSkip = false;


Now you have created a variable, that will ALWAYS tell you whether the player is currently on the skip or not! BUT: it won't do anything yet.
So, now you need to include an if-statement into all interactions that you want to disable when the player is on the skip:

Code: ags

if ( !PlayerIsOnSkip )
// if player is currently NOT on skip
{
   // do stuff
}


This way, you can also allow some interactions ONLY if the player is on the skip.

For closer information, re-read parts of the variables-tutorial.

Hope I could help.

ManicMatt

#2
Thanks, that's really helpful!

But I can't get it to work exactly right.



When on the skip he will follow about the first two commands AFTER the first "run script" and then use the script.

Am I going to have to take all that stuff that's been done in the interaction menu and type it out into one big script file? Would that do it? (If really time consuming and boring)

EDIT: Crap I just noticed the same thing happens regardless of whether he's on the skip or not..

DoorKnobHandle

#3
Yep, you'll have to learn all the real script commands and place them underneath your "cEgo.Say ( "Whatever" );" line!

It'll take some time, but don't worry - if you ever plan on becoming just a little more interested in coding more complex things (like custom GUIs etc.) you'll need to get rid of those "shortcuts" anyways.

EDIT: And you'll have to move the line "bool PlayerIsOnSkip" to the global room script file!

ManicMatt

#4
global room script file? Where is that???

Should I point out that the script you've seen is automatically placed in the global script anyway? Me confused.

Should my script have the "else" in it for when he's not on the skip?

EDIT:

I'm going to beat my head against a wall soon.

Please rectify!

function character9_c() {
  // script for Character 9 (Vagrant): Use inventory on character
bool PlayerIsOnSkip;
if ( !PlayerIsOnSkip ):
character[EGO].Say("I need to get down first.");
return;   {
}
else; {
character[EGO].Say("I don't need to get down first.");
}

DoorKnobHandle

To view the room script file (sorry for calling it global before, that way a typo), load up a room and hit CTRL+E.

Then make "bool PlayerIsOnSkip;" the first line there.

You can use else, but you'll still have to move all the interactions from the editor to the script!

ManicMatt

Thanks for clearing that up. I'll do that now.

Sorry, I mean it's saying "parsar error" about the else bit.

DoorKnobHandle

Get rid of the ; - an else-statement doesn't need one (as if's don't need any)!

Code: ags

if ( x == y )
{
   // do something
}
else
{
   // do something else
}

ManicMatt

It says:

parser error: unexpected "else"

PS - Good thing you're patient. You are patient, right?

(Note to self - must credit dkh in my game)

DoorKnobHandle

;D I am patient, I hope you are!

Also, delete the opening bracket ( { ) after the return; - line.

And delete the "bool PlayerIsOnSkip" and place it on top if that room script file (the CTRL+E one)! Then it should work!

ManicMatt

okay buddy, next problem! We'll get through this!  8)

function character9_c() {
  // script for Character 9 (Vagrant): Use inventory on character
if ( !PlayerIsOnSkip )
{
character[EGO].Say("I need to get down first.");
return;   
}
else
{
character[EGO].Say("I don't need to get down first.");
}
}

Just having the bool bit in the room script and not on the global one, as shown here, makes it say that playerisonskip is an undefined symbol.

DoorKnobHandle

Argh, sorry for this... I am really tired today.

Move that line again. This time out of the room script file and into the global script file (CTRL+G - (to the top). Then write this to the script header (CTRL + H):

Code: ags

import bool PlayerIsOnSkip;


Solving those problems is really hard when you don't have the game in AGS in front of you.

Hope it works now!

ManicMatt

next error message!:

unable to create local script: Runtime error: Unresolved import 'PlayerIs etc..'

What the heck does that mean?

DoorKnobHandle

Are you sure, that you have:

Code: ags

bool PlayerIsOnSkip;


at the top of your global script file (CTRL+G) and:

Code: ags

import bool PlayerIsOnSkip;


in your global header file (CTRL+H)?

This error shouldn't occur if you have both lines in place.

Sorry for being not so helpful, don't know what it is today...

ManicMatt

Don't worry about it, I'd be totally lost without you!

Yes, i believe so..

// main global script file
bool PlayerIsOnSkip;

and...

import bool PlayerIsOnSkip;
// Main header script - this will be included into every script in
// the game (local and global). Do not place functions here; rather,
// place import definitions and #define names here to be used by all
// scripts.


Does it matter that I'm using the most up to date AGS?

EDIT: (Cos I am!)

strazer

You have to export variables first so you can import them:

// main global script file
bool PlayerIsOnSkip;
export PlayerIsOnSkip;

ManicMatt

YES!!!!!!!!!  :D

That did it!

*Adds Strazer to the credits' thanks list*

Thanks a million guys! Now on to the commands...

(Don't worry, I should be able to handle it from here!)


DoorKnobHandle

Wait a second, how come that I don't have to export them??

I can just define and import them in the header! I double-checked.

strazer

Defining variables in the header creates separate instances of the variable for the global script and each room. Changing the value from within a room script then doesn't affect the variable in the global script.

So if you need global variables, define them in the global script, export them and import them in the global script header.

DoorKnobHandle

Ah yes, thanks a bunch. *knocks himslef* not my day today - did I already mention that? :=

SMF spam blocked by CleanTalk