Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   SImple Problem (https://forums.graalonline.com/forums/showthread.php?t=72667)

MrAnonymous_P2P 03-08-2007 05:50 AM

SImple Problem
 
Hey its me again, Try my hand on scripting Im getting the basics down but for some reason I am having trouble with this simple flag. Here is the first script:

PHP Code:

showcharacter;
  
setcharprop #3,head0.png;
  
setcharprop #C0,orange;
  
setcharprop #C1,white;
  
setcharprop #C2,blue;
  
setcharprop #C3,red;
  
setcharprop #C4,black;
  
setcharprop #2,shield1.gif;
  
shieldpower 1;
  
dir 2;
}
if (
playertouchsme) {move 26.5,-4,10,0;


freezeplayer 10;

sleep 10;

save[1]=true;


Then I have a door script:

PHP Code:

if (save[1]=true) {hide;} 

For some reason the door will not disapear though. Please help :)

Gambet 03-08-2007 05:52 AM

God it hurts me just to look at GS1 now that I've been working with GS2 for so long >_<



Are both parts in the same script? If not I don't think it would work because the flag would only be setting for that one script, and thus the other wouldn't be able to read it.

DustyPorViva 03-08-2007 05:55 AM

Don't really understand what you're trying to do... Could you explain it? I guess it has something to do with the save[x]'s... but I don't understand what.
From reading a little. I guess you have an NPC that will walk to a door and open it?

If that's the case, use triggeractions, not save[x]'s.
PHP Code:

if (created) {
  
showcharacter;
  
setcharprop #3,head0.png;
  
setcharprop #C0,orange;
  
setcharprop #C1,white;
  
setcharprop #C2,blue;
  
setcharprop #C3,red;
  
setcharprop #C4,black;
  
setcharprop #2,shield1.gif;
  
shieldpower 1;
  
dir 2;
}
if (
playertouchsme) {
  
move 26.5,-4,10,0;
  
freezeplayer 10;
  
sleep 10;
  
triggeraction x+1,y,opendoor,;


PHP Code:

if (actionopendoorhide

Though I don't remember if triggeractions work from one non-weapon NPC to another...

Twinny 03-08-2007 06:00 AM

Quote:

Originally Posted by DustyPorViva (Post 1286176)
Though I don't remember if triggeractions work from one non-weapon NPC to another...

It's triggering the map. Why wouldn't it work?

MrAnonymous_P2P 03-08-2007 06:05 AM

Still doesnt work. Remember Im a noob at scripting you might have to explain some things XD

DustyPorViva 03-08-2007 06:19 AM

Quote:

Originally Posted by Twinny (Post 1286177)
It's triggering the map. Why wouldn't it work?

Dunno, if I remember correctly, I had problems triggering from a non-weapon NPC to another NPC. I think it was having a block trigger a switch it was pushed over. Could never get it to work.

Chandler 03-08-2007 09:11 AM

I answered this in your other thread... re-read?

http://forums.graal2001.com/forums/s...09#post1285014

MrAnonymous_P2P 03-08-2007 03:35 PM

Im a noob at scripting I have no idea what all those commands mean. Please explain.(I dont know what to change to make it work or anything :( )

Chandler 03-08-2007 04:31 PM

PHP Code:

TRIGGERACTION npcxnpcyfoundPOSITION,; 

Change this to something like this.
PHP Code:

triggeraction 3030foundPOSITION,; 

Obviously, edit the position (30, 30) to where the door is. [The x/y position of the door]
Then, inside the door add the other script. You'll see how it works.

Kristi 03-08-2007 07:18 PM

Quote:

Originally Posted by MrAnonymous_P2P (Post 1286173)
Hey its me again, Try my hand on scripting Im getting the basics down but for some reason I am having trouble with this simple flag. Here is the first script:

PHP Code:

showcharacter;
  
setcharprop #3,head0.png;
  
setcharprop #C0,orange;
  
setcharprop #C1,white;
  
setcharprop #C2,blue;
  
setcharprop #C3,red;
  
setcharprop #C4,black;
  
setcharprop #2,shield1.gif;
  
shieldpower 1;
  
dir 2;
}
if (
playertouchsme) {move 26.5,-4,10,0;


freezeplayer 10;

sleep 10;

save[1]=true;


Then I have a door script:

PHP Code:

if (save[1]=true) {hide;} 

For some reason the door will not disapear though. Please help :)

PHP Code:

if (save[1]=true) {hide;} 

should be
PHP Code:

if (save[1]==true) {hide;} 

you used the wrong operator.
this method should work fine after that.

I can't believe all these FOOLS posting pointed you torwards triggeraction and completely overlooked that :D
jk ILU guys

Chandler 03-08-2007 07:28 PM

Quote:

Originally Posted by Kristi (Post 1286330)
PHP Code:

if (save[1]=true) {hide;} 

should be
PHP Code:

if (save[1]==true) {hide;} 

you used the wrong operator.
this method should work fine after that.

I can't believe all these FOOLS posting pointed you torwards triggeraction and completely overlooked that :D
jk ILU guys

I think you're mistaken ;)

Kristi 03-08-2007 07:33 PM

Quote:

Originally Posted by Chandler (Post 1286337)
I think you're mistaken ;)

as long as if(save[1]==true) is in a timeout it will be reconized

Alternately the door could be scripted in gs2!
PHP Code:

//#CLIENTSIDE

function onCreated() {
  
door942 this;
}

public function 
hideme() {
  
hide();


then from whatever script you want you can use
PHP Code:

function onPlayerTouchsMe() {
move(26.5,-4,10,0); 


freezeplayer(10); 

sleep(10); 

door942.hideme(); 



Kristi 03-08-2007 07:37 PM

Quote:

Originally Posted by Chandler (Post 1286340)
In a timeout! :p
Wouldn't you rather call something than check something every ## seconds?

READ THE EDIT

Besides, for all intensive purposes, he asked why his script did not work, not how to do it a better way.

zokemon 03-08-2007 09:07 PM

== is not required.
= works just fine.

napo_p2p 03-08-2007 09:12 PM

Quote:

Originally Posted by zokemon (Post 1286379)
== is not required.
= works just fine.

== is required.

= may have worked in GS1, but it acts a lot differently (as it should) in GS2.

For example:
PHP Code:

if (this.foo == 1

This checks if this.foo equals 1

PHP Code:

if (this.bar 1

This assigns the value '1' to this.bar and returns the value of this.bar after the assignment.

DustyPorViva 03-08-2007 10:38 PM

If the two scripts are in seperate NPCs, you just can't check save[0] from the other npc with save[0]==1. save[0] is local to the NPC, so you'd either have to get the NPC index for npcs[x].save[0]==1 or triggeraction the other NPC...
Now... if they're in the same NPC than triggeraction would be a silly solution.

Anyways, I see in his first post he corrected and captioned the second NPC is a door. In that case save[0]==1 will not work since save[x]'s are a local variable. Triggeraction is the right solution for NPC's interacting.

napo_p2p 03-08-2007 10:41 PM

Quote:

Originally Posted by DustyPorViva (Post 1286426)
Anyways, I see in his first post he corrected and captioned the second NPC is a door. In that case save[0]==1 will not work since save[x]'s are a local variable. Triggeraction is the right solution for NPC's interacting.

You can access the save[n] of another NPC, just like you can access any of its other variables. Joshie's solution shows how this can be done.

DustyPorViva 03-08-2007 10:52 PM

True, true... in GS2. But he posted a GS1 script and I responded with a GS1 solution. In GS1, triggeraction is the most sensible solution.

Andy0687 03-08-2007 11:21 PM

Quote:

Originally Posted by zokemon (Post 1286379)
== is not required.
= works just fine.

Thats really bad advice and a horrible habit to get into because it wont work as expected in any other language.

The question has been answered id like to hear from him again to see if he managed to fix it with the advice he was given.

MrAnonymous_P2P 03-09-2007 12:58 AM

1 Attachment(s)
Ok so first off thanks for all the help I did manage to solve it a different way.

I simply made the moving character drop the image of a stair case.(So it made it look like in magically appeared. The staircase had its own script with a drawunderplayer function and the player can now advance to the next level.

I couldn't quite figure out the trigger action function because I don't see how you use x,y coordinates to make an npc dissapear :( Perhaps I'm doing something wrong. If someone could please correct what I have done wrong it would be a great learning experience for me :)

Kristi 03-09-2007 04:24 AM

Quote:

Originally Posted by DustyPorViva (Post 1286455)
True, true... in GS2. But he posted a GS1 script and I responded with a GS1 solution. In GS1, triggeraction is the most sensible solution.

no, in gs1, saying save[0] = 1 will treat save as a global clientside array, all npcs clientside will be able to access save. if you said this.save, then it would be local, however, in gs1 clientside you cant have this.arrays, (last time i checked)

since this. was not use, the save[] array is accessable by all npcs on the clientside. Stop saying I am wrong when I am right please ^_^

Andy0687 03-09-2007 07:16 PM

Quote:

Originally Posted by MrAnonymous_P2P (Post 1286534)
I couldn't quite figure out the trigger action function because I don't see how you use x,y coordinates to make an npc dissapear :( Perhaps I'm doing something wrong. If someone could please correct what I have done wrong it would be a great learning experience for me :)

The NPCs you have on the level work fine using the triggeraction you have. After correcting the right npc (which didnt have a triggeraction) the door dissapeared after moving both of them.

Maybe you were just getting impaitent but you had to wait 10 seconds (sleep 10;) before the triggeraction would happen.

Crow 03-09-2007 09:01 PM

Quote:

Originally Posted by zokemon (Post 1286379)
== is not required.
= works just fine.

If you only check for single things, yes. If you want to do something like:

PHP Code:

if (this.blah == || this.blöh 2

You will need ==. A single = wont work here.

napo_p2p 03-09-2007 09:09 PM

Quote:

Originally Posted by Crow (Post 1286790)
If you only check for single things, yes.

No matter what, do not use = for comparing things...

MrAnonymous_P2P 03-20-2007 04:25 AM

Does triggeraction work in gs2? Its not working for me in this script

PHP Code:

function OnCreated() {

TRIGGERACTION (26.5,-4,hide,1);




xXziroXx 03-20-2007 04:31 AM

Quote:

Originally Posted by MrAnonymous_P2P (Post 1290870)
Does triggeraction work in gs2? Its not working for me in this script

PHP Code:

function OnCreated() {

TRIGGERACTION (26.5,-4,hide,1);




Your styling is horrible.. also, hide is text thus it should be wrapped in quotes. Right now its set to 0 since it thinks its a variable named "hide".

And hide == 0

PHP Code:

function onCreated() triggerAction(26.5, -4"hide"1); 


Twinny 03-20-2007 06:37 AM

Quote:

Originally Posted by MrAnonymous_P2P (Post 1290870)
Does triggeraction work in gs2? Its not working for me in this script

PHP Code:

function OnCreated() {

TRIGGERACTION (26.5,-4,hide,1);




As Ziro said, always place words in a string unless it's relating to an object. For instance, triggeraction(mousex, mousey, "fruit", "apples");

compared to
triggeraction(mousex, mousey, "owies", player.account, player.level.name);

Angel_Light 03-20-2007 02:13 PM

Quote:

Originally Posted by MrAnonymous_P2P (Post 1286173)
PHP Code:

if (save[1]=true) {hide;} 


wouldnt it be

PHP Code:

if (save[1]) {hide;} 

Since the if operations checks for true and false or

PHP Code:

if (save[1]==true) {hide;} 

since "=" is assign" and "==" is equals.

Twinny 03-20-2007 02:43 PM

Quote:

Originally Posted by Angel_Light (Post 1290983)
since "=" is assign" and "==" is equals.

Technically both will work but Kristi and Novo will hunt you with Tomahawks if you test with =.

[Edit]: haha i frigged this one up

Crow 03-20-2007 03:42 PM

Quote:

Originally Posted by napo_p2p (Post 1286796)
No matter what, do not use = for comparing things...

I dont do that, I just wanted to say that it works for single checks.

Angel_Light 03-20-2007 10:33 PM

Quote:

Originally Posted by Twinny (Post 1290985)
[Edit]: haha i frigged this one up

wth?

Twinny 03-20-2007 11:13 PM

Quote:

Originally Posted by Angel_Light (Post 1291080)
wth?

I messed up what I said so i changed it. You may have noticed Skyld's deleted post underneath with "Corrected".


All times are GMT +2. The time now is 02:03 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.