Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LocalVar and if-statements
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#1
LocalVar and if-statements

As you can read in the script. If all the machines are running the player can use the item on the area but if only 4 or less are you can't. I thought this script would work but it will not.

void OnStart()
{
for(int i=1;i<=6;i++){
AddUseItemCallback("UsingOrbPieces", "orb_piece_"+i+"", "AreaUseOrbPiece","UseOrbPiecesOnArea", false);
}
}


///Using the orb pieces///
void UseOrbPiecesOnArea(string &in asItem, string &in asEntity)
{
if(GetLocalVarInt("AllMachineryUpAndRunning") == 5)
{
RemoveItem(asItem);
AddLocalVarInt("OrbPutTogether", 1);
OrbAllDoneLocal();

}
else if(GetLocalVarInt("AllMachineryUpAndRunning") == 0 && GetLocalVarInt("AllMachineryUpAndRunning") == 1 &&
GetLocalVarInt("AllMachineryUpAndRunning") == 2 && GetLocalVarInt("AllMachineryUpAndRunning") == 3 && GetLocalVarInt("AllMachineryUpAndRunning") == 4)
{
SetMessage("Descriptions", "Hint_15", 3.0f);
PlaySoundAtEntity("", "27_thump.snt", "Player", 0.1f, true);
}
}

"What you think is irrelevant" - A character of our time

A Christmas Hunt
11-24-2012, 11:53 PM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#2
RE: LocalVar and if-statements

The message appears screwed up, i3670. I can't read the script.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
11-25-2012, 12:21 AM
Find
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#3
RE: LocalVar and if-statements

screwed up how?

"What you think is irrelevant" - A character of our time

A Christmas Hunt
11-25-2012, 12:23 AM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#4
RE: LocalVar and if-statements

It appears like:



void OnStart()

{

for(int i=1;i<=6;i++){

AddUseItemCallback("UsingOrbPieces", "orb_piece_"+i+"", "AreaUseOrbPiece","UseOrbPiecesOnArea", false);

}

}





///Using the orb pieces///

void UseOrbPiecesOnArea(string &in asItem, string &in asEntity)

{

if(GetLocalVarInt("AllMachineryUpAndRunning") == 5)

{

RemoveItem(asItem);

AddLocalVarInt("OrbPutTogether", 1);

OrbAllDoneLocal();



}

else if(GetLocalVarInt("AllMachineryUpAndRunning") == 0 && GetLocalVarInt("AllMachineryUpAndRunning") == 1 &&

GetLocalVarInt("AllMachineryUpAndRunning") == 2 &&
GetLocalVarInt("AllMachineryUpAndRunning") == 3 &&
GetLocalVarInt("AllMachineryUpAndRunning") == 4)

{

SetMessage("Descriptions", "Hint_15", 3.0f);

PlaySoundAtEntity("", "27_thump.snt", "Player", 0.1f, true);

}

}


Wait... what the heck? Anyway, you have a bigger script, right? If you have more from this machine, you should post it. Maybe the issue is somewhere else.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
11-25-2012, 12:29 AM
Find
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#5
RE: LocalVar and if-statements

Of course I have a bigger script but, I don't know if I feel like posting 250 lines of code when most of it is irrelevant to this part of the script.

"What you think is irrelevant" - A character of our time

A Christmas Hunt
11-25-2012, 12:32 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: LocalVar and if-statements

Do you realize that AllMachineryUpAndRunning can't be different numbers at the same time? So even though AllMachineryUpAndRunning doesn't equal 5, the else-if will never evaluate to true. Also, it may be necessary to know how AllMachineryUpAndRunning is incremented.

Tutorials: From Noob to Pro
(This post was last modified: 11-25-2012, 12:42 AM by Your Computer.)
11-25-2012, 12:40 AM
Website Find
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#7
RE: LocalVar and if-statements

Yes I do realize that the Local can't be different numbers at the same time but since I don't know how many machines the player has activated I did it like that and I do realize that those GetLocals are the problem, but how am I suppose to know how many the player has activated?

Edit: Shall I perhaps split it up so

else if Getlocal ==1

else if Getlocal ==2

"What you think is irrelevant" - A character of our time

A Christmas Hunt
(This post was last modified: 11-25-2012, 12:50 AM by i3670.)
11-25-2012, 12:47 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#8
RE: LocalVar and if-statements

You used && in your else-if statement. That's like saying, if AllMachineryUpAndRunning equals 0 AND equals 1 AND equals 2, etc, do this. If you used ||, then it would be like saying, if AllMachineryUpAndRunning equals 0 OR equals 1 OR equals 2, etc.

Tutorials: From Noob to Pro
11-25-2012, 12:59 AM
Website Find
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#9
RE: LocalVar and if-statements

Understood, changed, worked. Thank you YC.

"What you think is irrelevant" - A character of our time

A Christmas Hunt
11-25-2012, 01:03 AM
Find




Users browsing this thread: 1 Guest(s)