Home   Help Search Login Register  

Author Topic: Addaction  (Read 932 times)

0 Members and 1 Guest are viewing this topic.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Addaction
« on: 03 Sep 2004, 23:44:08 »
Hi there.

I want to have an action appear on the action menu when I hit a 1mx1m trigger.

I can get it so that the action appears, but it appears straight from the start of the mission.  >:(

I've done the obvious stuff like having the trigger set to west present. getdammage fodder >= 0.1
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Addaction
« Reply #1 on: 04 Sep 2004, 00:56:50 »
Occasionally triggers do go mad, in which case they should be deleted.    In this case there are two more realistic possiblities:  either the trigger is firing as soon as the mission starts, or the addAction command exists somewhere else that you've forgotten about.

Set the condition field of the trigger to false and see what happens.  
Plenty of reviewed ArmA missions for you to play

bored_onion

  • Guest
Re:Addaction
« Reply #2 on: 04 Sep 2004, 18:34:53 »
triggers do mess up like that sometimes
my initial idea would be to delete it and replace it with a clone

try adding this in the condition field:
Code: [Select]
player in thislist
so you can be sure some other western unit isnt activating it

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Addaction
« Reply #3 on: 04 Sep 2004, 18:39:19 »
u dont have 2 put player in thislist ;D

u can just group the triger 2 ur man ;D

LCD (old knowledges) OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

bored_onion

  • Guest
Re:Addaction
« Reply #4 on: 04 Sep 2004, 22:29:27 »
yeah that too  :P

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Addaction
« Reply #5 on: 04 Sep 2004, 22:55:24 »
well... yea :P

LCD (im just doin ma job) OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Addaction
« Reply #6 on: 22 Sep 2004, 18:06:29 »
You've completely lost me.

How's about somebody writes a setp by step tutorial.

Something simple like "switch on the radio"

You could justhave a example mission with a table and a radio.
You go up to it, an action appears "Switch on Radio"

You click the action, the radio comes on.

Its the only way people like me will learn.
Plus it would be a nice addition to the ed depot.

Cheers
 ;D
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Addaction
« Reply #7 on: 22 Sep 2004, 18:47:20 »
Lol I spot a frustrated mission designer whose mission doesn't work.    ;D    Think yourself lucky pal, I've spent the last 2 hours fixing something that used to work and now doesn't even though I haven't changed anything.

There are several helpful Comments on addAction in the online comref in the Ed Depot.  If you're having trouble with a command it's always worth looking there and also the trusty Unofficial comref.

Anyway, you don't need a trigger at all.   Here's what you do.  

Name the radio radio1.   In init.sqs:-

radioAction = radio1 addAction ["Switch on radio", "radio.sqs"]


You'll have to tell us what you mean by "switch on radio" if you want help with the script, but .....


; this script switches on the radio

radio1 removeAction radioAction

; stuff you want to happen

exit


Syntax not guaranteed.    Apart from "exit".
« Last Edit: 22 Sep 2004, 18:52:55 by macguba »
Plenty of reviewed ArmA missions for you to play

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Addaction
« Reply #8 on: 22 Sep 2004, 23:29:21 »
Don't even bother with the global vars, macguba. Take your own advise, and check the comments under the command :D. You will see that it returns the following:

_this select 0 -> object action was added to
_this select 1 -> unit that used the action
_this select 2 -> index of action (to be used with removeaction command)

So all you have to do is use this line in the action's script, and it will remove itself without the need for global variables:

(_this select 0) removeaction (_this select 2)

That way you could, say, have multiple radios doing the exact same thing, and not have to create a separate script for each one (to change the global var).
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Addaction
« Reply #9 on: 22 Sep 2004, 23:33:21 »
MUAHAHAHAHAHA you walked right into my trap GB, as I knew you would.

Actually, that's too many "_this select"s in one line for a syntax klutz like me.    Plus when I first learned addAction it didn't work.   And other non-valid excuses ....
Plenty of reviewed ArmA missions for you to play

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Addaction
« Reply #10 on: 22 Sep 2004, 23:49:50 »
Quote
Plus when I first learned addAction it didn't work.
Yeah, me too. :P Actually, the 'idx = addaction' didn't work either when I learned it, so I had to manually increment a global variable whenever I added or removed an action. Let's just say "(_this select 0) removeaction (_this select 2)" is a heck of a lot easier :D.

Now if only eventhandlers were that easy.... those things are even harder to remove than actions, because when you remove one, it changes the index of the rest of them! What were they thinking?! :crazy:
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Addaction
« Reply #11 on: 23 Sep 2004, 12:08:37 »
Once again you guys have baffled me.

I tired to understand the,
_this select 0

and all thatbut even reading the stuff about it in the Ed depot didn't help e understand it.

WhatI need is a tutorial which gives step by step dummy instructions, telling me what to do and why I'm doing it.

If I actually copy the stuff into a sample mission I'll eventually get the hang of it.


At this particular time, what I'm trying to do is very complicated. For me anyway.

Here goes.

I want to walk into a room in a small building and go over to a computer. When I get there I want an action to appear which gives me the option to switch off mains supply.

When I click the action (Switch off Mains Supply), I want the lights in the village to go off and the action "Switch on Mains supply" to appear.

I can find out the IDs for the lights simple enough, its the addaction and the script line for the lights I'm stuck with.

I'm sorry to keep going on about addaction.

Macguba is dead right my mission won't work until I get this sorted.  :(
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Addaction
« Reply #12 on: 23 Sep 2004, 17:21:24 »
Ok I did what you suggested Macguba.

The thing works now. Unfortunatly I don't know exactly what I did. I just copied.

I'm happy.  ;D For now at least.  ;)
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Addaction
« Reply #13 on: 23 Sep 2004, 17:50:05 »
It took me ages to get the hang of the whole "_this" thing.     This is not a syntax or code question at heart:  it's a concept.   Needless to say it has nothing in particular to do with addAction, but we'll come on to how it applies to addAction in a minute.

Every time a script starts, an array is created.    The array is local to the script, so its name starts with an underscore.    The name of the array is _this.    

When some scripts start, the array _this is empty.    

Sometimes, _this has a bunch of stuff in it.   You know you sometimes call a script like this?

[loon1, bmp1] exec "whatever.sqs"

Well the stuff in the square brackets gets put into _this when the script starts.    

STOP!   Go back and read all that again.   Happy so far?    Good.




Now, to pick an element out of an array and do something to it, you need the command select.     Arrays start numbering their elements at 0, rather than 1, so the first element has the index 0.    

Let's say your script whatever.sqs is going to do something to loon1.   You want to assign a local variable within the script that refers to loon1.  Here's how you do it:

_victim = _this select 0

The local variable _victim now refers to the first element (numbered 0, if you recall) of the array _this.     We know that _this is the stuff that was sent to the script, ([loon1, BMP1]) and that the first element was loon1, so _victim now refers to loon1.

STOP!    Read through all that again.  I hope it makes sense.    Look up the command select in the comref.



That's all well and good, you say, but what's this got to do with addAction?   Well, addAction is a jolly clever little command.    Or rather, the people who designed the code are jolly clever and this same trick turns up all over the place in OFP code.    

When you start a script by using an action, the script starts as usual.   Fine.   Does this script have an array _this like other scripts?   Yes it does.

Ah-ha, but how can it, when there were no square brackets [] anywhere?   How can _this not be empty when we haven't passed anything into the script?    Well here's the clever bit.   A whole bunch of useful stuff is passed automatically into _this.     The useful stuff in the case of a script called from an Action is

- the object to which the action is attached (in other words, the object that had the original addAction command)

- the dude that did the action (usually the player but not always)

- the index of the action  (an object can have more than one action added to it:  each action added gets an index number)

So we've got some shorthand here.    The addAction command really works a bit like this, but the bits in blue don't appear - they are automatic.

radio1 addAction ["Switch on radio", "[the object to which the action is attached, the loon that did the action, action ID] exec radio.sqs"]

STOP!   I guess you know by now what to do when I shout stop ....



When the action is done the script starts and the array _this is created with the relevant information in it.    _this has the three elements mentioned above, in that order.   (Remember that the first thing is always numbered 0 rather than 1.)   In other words, in our script the following line has happened.  It's automatic and invisible, so you don't see it happen and you don't write it down.  

_this = [object to which action was attached, dude who did action, action ID]

So now we come to General Barron's mysterious command:-

(_this select 0) removeaction (_this select 2)

Which, as you can now figure out, translates as:-

(object to which action was attached) removeAction (action ID)




The reason you had trouble understanding all this is that it has very little to do with addAction.    In fact a really good addAction tutorial would cover virtually none of what I've just written.     Firstly you need to understand about arrays, and then about how scripts are called.    Once you understand that, the way it applies to addAction is obvious.

I hope this has cleared things up a little.      If any of this is unclear, ask again.     It's one of these things that is utterly incomprehensible the first three times you read it, then two days later on the bus you suddenly think "duh-oh, that's so obvious".


« Last Edit: 23 Sep 2004, 18:13:26 by macguba »
Plenty of reviewed ArmA missions for you to play

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Addaction
« Reply #14 on: 24 Sep 2004, 16:37:02 »
Cheers Macguba. I could feel it sinking in a little after the third read.
I'll add the thread to y favorites and keep at it.

It'll be a question of learning the structure of the syntax I think.

My head is gonna hurt at the end I feel.  :-\
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."