Some Newbie Questions about Scripting

Started by kampfkaese, Sun 27/07/2014 22:35:32

Previous topic - Next topic

kampfkaese

Hello!

Because i have many Problems which i sometimes cannot solve for myself, i wanted to start one Thread for some different Questions.

My first Question is that i want to call an object from my Room2 in the Globalscript.. This is not possible because Globalscript cannot recognise my Room Specific Objects...

Here is my Sourcecode:

Code: AGS
function Kater_UseInv()
{
  if ( (player.ActiveInventory==inventory [7]) || (player.ActiveInventory==inventory [4]) ) 
    {     
    if (Kater.Room==2)
      {
       if ((player.HasInventory(Napfivoll)) && (player.HasInventory(essenfertig)) )
          {    
            cEgo.Walk(555, 356,  eBlock);
            wassernapf.visible=true; // <- Here is the Problem! What to do with it?!
            volleschale.visible=true; // <- Here is the Problem! What to do with it?!
            cEgo.Walk(505, 380);
            Kater.Walk(603, 325,  eBlock); 
            
          }  
       else
          {
          Display("Die Katze braucht Wassser -und- Nahrung.");
          }
      }
    else
      {
      Display("Geh Küche");
      }
   
    }
  else
  {
    Display("Das möchte er nicht..");
  }
}


The Errormessage is:

Quote
GlobalScript.asc(265): Error (line 265): Undefined token 'wassernapf'

Khris

It's funny, because you're already using the solution, just in the wrong place.

InventoryItems are global, which means you can use their names in the GlobalScript instead of having to use inventory[7] or inventory[4].
Objects and hotspots are tied to their rooms though, so you have to use hotspot[id] and object[id].

NickyNyce

#2
Pretty sure this code won't work with those double (( after your if's, not to mention a few more misplaced ones too.

Khris

#3
The additional brackets won't make a difference. They are superfluous though and should be omitted because adding them is error prone. I'm not seeing misplaced ones though. What I see is completely arbitrary and inconsistent indentation though.

Code: ags
function Kater_UseInv()
{
  if (player.ActiveInventory == Napfivoll || player.ActiveInventory == essenfertig)
  {     
    if (Kater.Room == 2)
    {
      if (player.HasInventory(Napfivoll) && player.HasInventory(essenfertig))
      {    
        cEgo.Walk(555, 356,  eBlock);
        object[0].Visible=true; // <- change ID to match wassernapf
        object[1].Visible=true; // <- change ID to match volleschale
        cEgo.Walk(505, 380);
        Kater.Walk(603, 325,  eBlock);
      }  
      else
      {
        Display("Die Katze braucht Wassser -und- Nahrung.");
      }
    }
    else
    {
      Display("Geh Küche");
    }
  }
  else
  {
    Display("Das möchte er nicht..");
  }
}


It's also advisable to call the objects "oWassernapf" and "oVolleschale", and the inventory items "iNapfvoll" and "iEssenfertig".
And to post code, use [code=ags] .. [/code]

Edit: fixed code

NickyNyce

I learn something new around here on a daily basis from you guys. I had no idea that extra brackets wouldn't cause a problem. Sorry for that. I should have known that you don't miss these things.

Crimson Wizard

Quote from: NickyNyce on Mon 28/07/2014 11:44:39
I learn something new around here on a daily basis from you guys. I had no idea that extra brackets wouldn't cause a problem. Sorry for that. I should have known that you don't miss these things.
They should be paired, but that's it.

Also, it is object[0].Visible, not object[0].visible.

kampfkaese

Thank You!! Now everything works fine... It was really very easy..


Next Problem:

How would you let a character move permanently, without blocking the Script or using a seperate Animation? I Tried to let the Cat walk onto A Hotspot which sends the Cat to another Hotspot, which sends it back just via "cCat.walk()" and "Stands on Hotspot", but nothing happens when the cats arrived at Hotspot 1..

Khris

You're supposed to use Regions for stuff like that; the "stands on hotspot" event is only included for backwards compatibility and will trigger every game frame / 40 times per second, just like "while player stands on region". Which means the .Walk command is also called 40 times per second, which makes the character get stuck because they constantly start their walk over again.

kampfkaese

Another Problem:

I want to let the cat jump out of the window when the Player feedet the cat. For that reason i used an if question if int Feed=1, when Player interacts with the closed Windows Animation Object. But the Game doesnt Recognize "Feed" even if i set "Feed=0" in Global script at the beginning.

Code in Room2.asc

Code: ags

function fclose_Interact()
{
if (Feed==1)                 // Check 
{
  Display ("Walkto, Sprunganimation, etc.");
}
else{
fclose.Visible=false;
fopen.Visible=true;
}
}


Code in Globalscript.asc:

Code: ags

function Kater_UseInv()
{
  if ( (player.ActiveInventory==inventory [7]) || (player.ActiveInventory==inventory [4]) )
    {     
    if (Kater.Room==2)
      {
       if ((player.HasInventory(Napfivoll)) && (player.HasInventory(essenfertig)) )
          {    
            cEgo.Walk(555, 356,  eBlock);
            object[9].Visible=true;
            object[10].Visible=true;
            int Feed=1;                     // Declaration
            cEgo.Walk(505, 380);
            Kater.Walk(603, 325,  eBlock);
            Kater.ChangeView(6);
            Kater.Animate(0, 6);
            Kater.Animate(0, 6);
            Kater.ChangeView(3);
            Kater.Walk(466, 384,  eBlock);
            Kater.ChangeView(4);
            Kater.Walk(444, 244,  eBlock,  eAnywhere);
            Kater.ChangeView(3);
            Kater.Walk(320, 247);
            
          }  
       else
          {
          Display("Die Katze braucht Wassser -und- Nahrung.");
          }
      }
    else
      {
      Display("Ich füttere die Katze besser in der Küche.");
      }
   
    }
  else
  {
    Display("Das möchte er nicht..");
  }
}


The code and the Animation is not yet ready its just some Brainwork, to get it sorted.. I make it better when eveything is working and at the right place :)

Slasher

#9
One way:

You could make an int variable (Feed) in the global pane and set it to 0.

Feed would then be recognized in every room.

Once you make Feed=1 you can then use
Code: ags

{ 
 if (Feed==1) // if Feed value has been changed to 1
{
 // Do this if Feed=1 
}
}


Even have else if and else statements if required.

If you are going to have Feed=2, Feed=3 etc then an Int is what you want else a boolean would do as false or true.

afaik a variable must be declared before you can use it ie above where it is to be used.




kampfkaese

Quote from: slasher on Tue 29/07/2014 13:17:51
One way:

You could make an int variable (Feed) in the global pane and set it to 0.

Feed would then be recognized in every room.

Once you make Feed=1 you can then use
Code: ags

{ 
 if (Feed==1) // if Feed value has been changed to 1
{
 // Do this if Feed=1 
}
}


Even have else if and else statements if required.

If you are going to have Feed=2, Feed=3 etc then an Int is what you want else a boolean would do as false or true.

afaik a variable must be declared before you can use it ie above where it is to be used.

Thanks! i did not know where to declare it.

Found it!

kampfkaese

#11
Quote from: Khris on Tue 29/07/2014 02:47:02
You're supposed to use Regions for stuff like that; the "stands on hotspot" event is only included for backwards compatibility and will trigger every game frame / 40 times per second, just like "while player stands on region". Which means the .Walk command is also called 40 times per second, which makes the character get stuck because they constantly start their walk over again.

I Tried using Region now but no difference. When the Cat walks onto the region nothing happens when i use "While Standing on, do..."

Code: ags

function region1_Standing()
{
cEgo.Walk(219, 244);
cEgo.Walk(500, 244);

}


The cat should walk on the Table from the left vorner to the right, and back

Another Problem:

The Check for a Variable Set to 1 wont function either..
Now the declared Variable wont lead to an error message but The If Check Doesn't Work.

Code: ags

function fclose_Interact()
{
  if (Feed==1) // Ignored by AGS or was not transferred from Global Script to Room Script or RAM or What else :D
    {
    cEgo.Walk(400, 386, eBlock);
    fclose.Visible=false;
    fopen.Visible=true;
    Kater.Walk(485, 248, eBlock);
    Kater.ChangeView(7);
    Kater.Move(331, 164,  eBlock, eAnywhere);
    Kater.ChangeView(9);
    Kater.Move(316, 216,  eBlock, eAnywhere);
    Kater.ChangeView(8);
    }
    else
    {
    cEgo.Walk(400, 386, eBlock);  
    fclose.Visible=false;
    fopen.Visible=true;
    }
}

Slasher

#12
QuoteI Tried using Region now but no difference. When the Cat walks onto the region nothing happens when i use "While Standing on, do..."
Quote from: Khris on Tue 29/07/2014 02:47:02
You're supposed to use Regions for stuff like that; the "stands on hotspot" event is only included for backwards compatibility and will trigger every game frame / 40 times per second, just like "while player stands on region". Which means the .Walk command is also called 40 times per second, which makes the character get stuck because they constantly start their walk over again.

Exactly as Khris told you why it won't work!

If this walk (the Cat) is back and forth you should look at AddWayPoint in the manual, use it to patrol back and forth (I have used this myself a number of times). You may also want to check out DoOnceOnly in the manual, it's handy to know. Or combined with if and boolean, whatever.

As for your script, you need to make Feed=1 first before you can declare it in an if.

Code: ags


// Some script here in a function that will make Feed==1
Feed=1; // now you can declare Feed==1


As Khris will tell you: The manual is your Bible, read it then read it again..

I'm far from perfect but always try to get / work out the answer myself if I can....




kampfkaese

#13
Thank you for that Waypoint thing! That sounds perfect.

The thing  about variable declaration.... ok i searched the manual another time since i posted this post. I think there should be a complete scripting Workshop, not just 2 Pages with 4 examples -.- I never found something that explains the script language from first Hello World - over - variables - to - Arrays, just single Pages which are not linked. Then there is the Language Barrier.

It would really help me if somebody would now a complete Step - by - step tutorial for the Programming language... With the most common fields of use...
Some Kind of working game complete with Roomchanges, different Detection methods, Inventory etc from the first step, to a Working 2- Room Game with openable Cabinets with hidden objects, Transparent Characters, eblock, eAnywhere, Variables, If switches, working Speech etc...

I did not find any... I have a code referrence, which dosnt Explain anything but has everything listed:

Scripting Reference, where i did not find something detailled about Variables, but the two pages about Object and Character Properties

And the Manual which explains first steps (Placing objects changing rooms etc) and Many different Points with no direct Relation to another



It Would be handy if Somebody would have a complete step by step tutorial about scripting...

Does any?

Sorry my english is not THAT.. good :D

Thanks

Slasher

#14
Your biggest problem would be the language barrier.

Everybody starts from either no knowledge (me) or some knowledge if they can program computer languages or have studied very hard the ags scripting language..

Indeed the manual may not cover every aspect but it is a place to start. There is also the wiki and the online manual which has just been improved and of course a lot of answers can be found by searching here on the forums.

Of course there will be times when you need additional help, I do quite often and there are people here that know their stuff and will help you as long as you don't come across as lazy or ask stupid questions.

Step-by-step guide may sound fine but in practice...

I'm amazed at how some newbees want to run a marathon without first learning to walk...

I can't say I've mastered ags scripting but some knowledge helps you see the bigger picture and helps you get there. Like if you have an idea in your head and being able to achieve it with minimum fuss, but crap happens along the way sometimes.

Start small and learn to walk before trying to run....

* Khris (for example) himself studied the manual again and again.. and it shows (nod) even if he has kicked my butt in the passed, I'm better for it (laugh)... and there are many others here.

Of course, in an ideal world, everything would be ready mapped for us ;)

So, keep reading and learning and game making ;)




kampfkaese

Hey, thanks!

Maybe I'll find something in German Forums, i never really searched for it.

Anyway, no matter how difficult it is to understand with the wiki and so on, big thanks to the community. On Other Forums i would be warned for my multiple Questions and would not be allowed to make a Thread for Different Questions like here.

Cassiebsg

The online manual is 1000000 times better than the Wiki. ;) http://www.adventuregamestudio.co.uk/manual/

And  densming's YouTube tutorial should help you out some, though not everything is there, but enough should be so you can get the more basic questions answered: http://www.youtube.com/playlist?list=PL21DB402CB4DAEAEF
There are those who believe that life here began out there...

Khris

I must have been really tired when I posted this. NPCs don't trigger Region events, and that's the reason the cat won't walk. If they did though, you would have to use "walks onto" as opposed to "while standing on".
What you have to do instead is use timers; you check for the region at the cat's feet, then send him to the next region and set the timer again. This will prevent the command from getting called repeatedly:
Code: ags
function room_RepExec() {
  Region *r = Region.GetAtRoomXY(Kater.x, Kater.y);
  if (Kater.Room == player.Room) {
    if (IsTimerExpired(1)) {
      if (r.ID == 1) {
        Kater.Walk(...); // send to next region
        SetTimer(1, 200);  // prevent the above command from running again immediately
      }
      ...
    }
  }
}

You can start this by placing Kater on a region and calling SetTimer(1, 1) in after fadein.

Regarding scripting: neither AGS nor the manual is supposed to teach you how to program. I understand that it can be quite a challenge to use AGS as someone who has never programmed before, but you are creating adventure games, not paper airplanes.


kampfkaese

#19
Quote from: Khris on Tue 29/07/2014 18:56:43
I must have been really tired when I posted this. NPCs don't trigger Region events, and that's the reason the cat won't walk. If they did though, you would have to use "walks onto" as opposed to "while standing on".
What you have to do instead is use timers; you check for the region at the cat's feet, then send him to the next region and set the timer again. This will prevent the command from getting called repeatedly:
Code: ags
function room_RepExec() {
  Region *r = Region.GetAtRoomXY(Kater.x, Kater.y);
  if (Kater.Room == player.Room) {
    if (IsTimerExpired(1)) {
      if (r.ID == 1) {
        Kater.Walk(...); // send to next region
        SetTimer(1, 200);  // prevent the above command from running again immediately
      }
      ...
    }
  }
}

You can start this by placing Kater on a region and calling SetTimer(1, 1) in after fadein.

Regarding scripting: neither AGS nor the manual is supposed to teach you how to program. I understand that it can be quite a challenge to use AGS as someone who has never programmed before, but you are creating adventure games, not paper airplanes.

Thank you!

(and cassie and the one with the Book! too)

Edit:
"Juhuuuuu" xD It Worked!

Code: ags

function fclose_Interact()
{
  Region *Feedi = Region.GetAtRoomXY(Kater.x, Kater.y);
    if (Feedi.ID == 1) 
    {
    cEgo.Walk(400, 386, eBlock); 
    fclose.Visible=false; 
    fopen.Visible=true;
    Kater.Walk(485, 248, eBlock); 
    Kater.ChangeView(7);
    Kater.Move(331, 164,  eBlock, eAnywhere);
    Kater.ChangeView(9);
    Kater.Move(316, 216,  eBlock, eAnywhere);
    Kater.ChangeView(8);
    }
    else
    {
    cEgo.Walk(400, 386, eBlock);  
    fclose.Visible=false;
    fopen.Visible=true;
    }
}


SMF spam blocked by CleanTalk