i3670
Posting Freak
Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation:
36
|
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);
}
}
|
|
11-24-2012, 11:53 PM |
|
The chaser
Posting Freak
Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation:
113
|
RE: LocalVar and if-statements
The message appears screwed up, i3670. I can't read the script.
THE OTHERWORLD (WIP)
Aculy iz dolan.
|
|
11-25-2012, 12:21 AM |
|
i3670
Posting Freak
Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation:
36
|
RE: LocalVar and if-statements
screwed up how?
|
|
11-25-2012, 12:23 AM |
|
The chaser
Posting Freak
Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation:
113
|
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)
Aculy iz dolan.
|
|
11-25-2012, 12:29 AM |
|
i3670
Posting Freak
Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation:
36
|
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.
|
|
11-25-2012, 12:32 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
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.
(This post was last modified: 11-25-2012, 12:42 AM by Your Computer.)
|
|
11-25-2012, 12:40 AM |
|
i3670
Posting Freak
Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation:
36
|
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
(This post was last modified: 11-25-2012, 12:50 AM by i3670.)
|
|
11-25-2012, 12:47 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
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.
|
|
11-25-2012, 12:59 AM |
|
i3670
Posting Freak
Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation:
36
|
RE: LocalVar and if-statements
Understood, changed, worked. Thank you YC.
|
|
11-25-2012, 01:03 AM |
|
|