Home   Help Search Login Register  

Author Topic: Need help initializing a variable!!  (Read 555 times)

0 Members and 3 Guests are viewing this topic.

Offline Arctic

  • Members
  • *
  • In Utero
Need help initializing a variable!!
« on: 31 Dec 2002, 06:11:15 »
Lol, same problem with all of my scripts. I can never figure out how to initialize variables!  :-\

I am trying to make a sensor script for a mission i am working on.

Main script file:
Code: [Select]
;SensorInit.sqs

_User = _this select 0
_mrkr = _this select 1
_mX = getpos _mrkr select 0
_mY = getpos _mrkr select 1
_mZ = getpos _mrkr select 2
_CountTrig = _this select 2
_refreshrate = 7

#Menu
[] exec "Menu.sqs"
goto "Controller"

#Controller
if (Psensor
@PlaceNow
_mrkr getpos _User select 0
_CountTrig getpos _mrkr select 0

?(PlaceNow = False): goto "RemoveSensor"
goto "Plant"

#Plant
_illus = "pipebomb" CamCreate [_mX,_mY,_mZ]

~1.25
_spikes = list _CountTrig
hint format ["Sensor Hits: %1",_spikes]

~15.5
_abab = True
goto "Refresh"

#Refresh
@abab
hint format ["Time until next count: %2",_refreshrate]

_refreshrate = _refreshrate - 1

~1
_abab = False
?(_refreshrate == 0): goto "Controller"
goto "Refresh"

#RemoveSensor
deleteVehicle _illus

~1.05
goto "Controller"

I am recieving errors about the PlaceNow variable.

Second important script file:

Code: [Select]
;Menu.sqs

#RadioLoop
player addAction ["Place Sensor","Psensor.sqs"]

@PlaceNow
player addAction ["Remove Sensor","Rsensor.sqs"]

?PlaceNow: goto "Recycle"

#Recycle
~2
goto "RadioLoop"

Code: [Select]
;PSensor.sqs

player removeAction 0

PlaceNow = True
exit

and finally:

Code: [Select]
;RSensor.sqs

player removeAction 1

PlaceNow = False
exit
--------------------------

I know I suck at scripting... but i think i am getting better!!  ::)
  I hope someone out there can help explain (or at least shed some light) on how to initialize the variables. *crosses fingers*
 Thank you all for putting up with my scripting questions!!!



Liquid_Silence

  • Guest
Re:Need help initializing a variable!!
« Reply #1 on: 31 Dec 2002, 08:30:52 »
It's this line:
Code: [Select]
?(PlaceNow = False):
it should be:
Code: [Select]
?(!PlaceNow)
btw:
Code: [Select]
if (Psensor <- this doesn't actually look like this in the script does it?

Code: [Select]
#Refresh
@abab
should be
Code: [Select]
#Refresh
@_abab

Hope this gets rid of most of the bugs :) I wrote this under time pressure so I might not have gotten all of them...gotta go now...good luck

Offline Arctic

  • Members
  • *
  • In Utero
Re:Need help initializing a variable!!
« Reply #2 on: 31 Dec 2002, 17:11:06 »
That worked! yay!

I've tweaked the script a little... but I have found a problem. The trigger doesnt go to the right spot!

Code: [Select]
;SensorInit.sqs

_User = _this select 0
_mrkr = _this select 1
_mX = getpos _mrkr select 0
_mY = getpos _mrkr select 1
_mZ = getpos _mrkr select 2
_CountTrig = _this select 2

#Menu
[] exec "Menu.sqs"
goto "Controller"

#Controller
@PlaceNow
_mrkr setpos getpos _User
_CountTrig setpos getpos _User

?(!PlaceNow): goto "RemoveSensor"
goto "Plant"

#Plant
_illus = "pipebomb" CamCreate [_mX,_mY,_mZ]

~1.25
_spikes = list _CountTrig
_spikeM = "Men" countType _spikes
_spikeC = "Car" countType _spikes
_spikeA = "Tank" countType _spikes
hint format ["Sensor Hits\n Men: %1 Car: %2 Armour: %3 ",_spikeM,_spikeC,_spikeA]

~15.5
_abab = True
_refreshrate = 7
goto "Refresh"

#Refresh
@_abab
hint "Sensor is reinitializing..."

_refreshrate = _refreshrate - 1

~1
?(_refreshrate <= 1): _abab = False; goto "Plant"
goto "Refresh"

#RemoveSensor
deleteVehicle _illus

~1.05
goto "Controller"

I figured out that the trigger (and marker) weren't going to the right spot b/c the satchel charge (illus) was going to the player's starting location!

Code: [Select]
;Menu.sqs

#RadioLoop
player addAction ["Place Sensor","Psensor.sqs"]

@PlaceNow
player addAction ["Remove Sensor","Rsensor.sqs"]

?(_RRN): goto "Recycle"

#Recycle
@_RRN

~7
_RRN = False
goto "RadioLoop"

Code: [Select]
;PSensor.sqs

player removeAction 0

PlaceNow = True
exit

Code: [Select]
;RSensor.sqs

player removeAction 1

PlaceNow = False
_RRN = True
exit
-------------------------

***Should this be in Scripting: Beta Testing now?***







Offline Ranger

  • Members
  • *
  • Hoo-ah!
Re:Need help initializing a variable!!
« Reply #3 on: 01 Jan 2003, 00:08:20 »
Quote
I figured out that the trigger (and marker) weren't going to the right spot b/c the satchel charge (illus) was going to the player's starting location!

That's because of the order of your variable initialization.  I will guess that at the start of your mission, the marker is at the same location as the player's starting location.  If that is so, then there's your problem.  Look at your code again.

At the start of your script, you assign values to to _mx, _my, and _mz.  Later in the script, you move the marker to the player's current position, but you do not update the coordinate variables.  Thus, when it comes time to camCreate your explosive, it is still using the original x, y, and z coordinates that you attained *before* you moved the marker.

To fix this, simply move the

Code: [Select]
_mX = getpos _mrkr select 0
_mY = getpos _mrkr select 1
_mZ = getpos _mrkr select 2

code after the

Code: [Select]
_mrkr setpos getpos _User

line.

You seem to have some extraneous code in your script that I can't figure out why you have it.

Code: [Select]
#Menu
[] exec "Menu.sqs"
goto "Controller"

#Controller

I suppose this is good coding practice what you did here, but since #Controller follows #Menu without any extra code inbetween, there's no need to have the goto "Controller" line.  I guess it's personal preference.

Code: [Select]
@PlaceNow
_mrkr setpos getpos _User
_CountTrig setpos getpos _User

?(!PlaceNow): goto "RemoveSensor"

Does goto "Removesensor" ever get called?  The @PlaceNow line should only be fulfilled when PlaceNow == true, but when PlaceNow == true, then the if-then statement won't be true.  Since you don't have a delay between the wait and the if-then statements to allow some other code to change PlaceNow to false, and since PlaceNow is not changed to false before the if-then statement within this script, I don't see how the if-then  statement will ever be fulfilled.

Code: [Select]
goto "Plant"

#Plant

Same deal about the goto.

Code: [Select]
goto "Refresh"

#Refresh

Same deal about the goto.
Ranger