Home   Help Search Login Register  

Author Topic: Little Script help :D  (Read 711 times)

0 Members and 1 Guest are viewing this topic.

Offline Ding

  • Contributing Member
  • **
  • Jurassic Park
Little Script help :D
« on: 21 Jul 2005, 08:36:33 »
hi, in this script, i am trying to make a reusable script for taking money, ok here is the script so far:

;;UniMoney1.sqs
_unit = _this select 0
_money = _this select 1
_action = _this select 2

_Action = _unit addaction ["Take Money", "TakeMoney.sqs"]

;;takeMoney.sqs
deletevehicle _money
money = money + 40
hint format ["Players Money is %1$", Money]
removeaction _Action

Now i know that i have done somthing wrong with the _Action, when ingame a create a trigger saying this -

[man1, money1, TakeMoney1] exec "UniMoney1.sqs

I have done somthing wrong in this script can someone point out what it is, and tell me how to fix it, thanks :D

"If I remain lost and die on a cross, atleast I wasn't born in a manger"

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Little Script help :D
« Reply #1 on: 21 Jul 2005, 08:59:41 »
when you use an underscore ( _ ) it makes a variable local, that is, it is only used within the script where it is defined, and outside that script it ceases to be.

in 'unimoney.sqs' you define _money as a local variable, but want it to be seen in 'takemoney.sqs' too. remove the underscore to make it a global variable, and it should work.

similarly, 'removeaction _action' won't work, because of the same problem described above. variables for use between scripts need to be global, so no underscores - also it's

Code: [Select]
unit_name removeaction action_id
;)

Offline Ding

  • Contributing Member
  • **
  • Jurassic Park
Re:Little Script help :D
« Reply #2 on: 21 Jul 2005, 09:20:06 »
Ok ive edited it a bit, i have worked out what the problem is:

This part all works the way i want it to:

;;uniMoney1.sqs

_unit = _this select 0
_money = _this select 1
_action = _this select 2

_Action = _unit addaction ["Take Money", "TakeMoney.sqs"]

But this next part is the problem:

;;takeMoney.sqs
_Unit = _this select 0
_money = _this select 1
_action = _this select 2

deletevehicle _money
money = money + 40
hint format ["Players Money is %1$", Money]
player removeaction _Action

Ok the bottom 3 lines of the takemoney.sqs script work,
but the
deletevehicle _money
command dosent work for some reason, im getting no error messages either.

"If I remain lost and die on a cross, atleast I wasn't born in a manger"

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Little Script help :D
« Reply #3 on: 21 Jul 2005, 11:10:35 »
as i stated before, variables with an underscore are local variables. thus 'takemoney.sqs' will not know what _money is, especially since you don't pass any variables to the script like you do with 'unimoney.sqs'.

you call 'unimoney'.sqs' like this -

Code: [Select]
[man1, money1, TakeMoney1] exec "UniMoney1.sqs"
which passes on the variables. but in calling 'takemoney.sqs' from an action, you can't pass it variables. so when you put

Code: [Select]
_Unit = _this select 0
_money = _this select 1
_action = _this select 2

those local variables reference something altogether different. see the addaction command for what those local variables return...

« Last Edit: 21 Jul 2005, 11:11:41 by bedges »

Offline Ding

  • Contributing Member
  • **
  • Jurassic Park
Re:Little Script help :D
« Reply #4 on: 21 Jul 2005, 12:13:18 »
so what i should have is this? :
I tried this one and it removes the action but it dose not delete _man
;;;
_obj = _this select 0
_man = _this select 1
_index = _this select 2

_index = _obj addaction ["Take Money", "TakeMoney.sqs"]

;;;TakeMoney.sqs
_obj = _this select 0
_man = _this select 1
_index = _this select 2

deletevehicle _man
money = money + 40
hint format ["Players Money is %1$", Money]
_obj removeaction _Index

;;;


"If I remain lost and die on a cross, atleast I wasn't born in a manger"

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Little Script help :D
« Reply #5 on: 21 Jul 2005, 12:31:16 »
to repeat -

Quote
in calling 'takemoney.sqs' from an action, you can't pass it variables.

so '_this select' in 'takemoney.sqs' is pointless. use global variables...

 ::)