Author Topic: Question on Variables  (Read 2666 times)

0 Members and 1 Guest are viewing this topic.

Okay, for a mission I'm making (for FA academy). What I'm doing is I'm giving a ship several possible waypoint paths depending on the situation. So for each possibility, I have an event. But in order to ensure that other events aren't introduced after the first correct one I'm trying to use a variable.

    Basically, one of the conditions of the events going off is that a numeric variable has value < 1. Then when an event works, the value is supposed to be increased by 1 (from 0 to 1), therefore, invalidating the other events.

     I was just wondering if my code was cool:

conditional:

--op  <
    --courseconfirm(0)
    --0

**Meaning: If variable's value is less than one, return true

modifier to variable:

--op modify-variable
    |--courseconfirm(0)
    ---op +
        --- 1
        --- 0

**Meaning: Take variable, and add a value of 1 to it. Making it "1" and invalidating the conditional (above).

   
      Does this jive or no?

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
Quote
Originally posted by Akalabeth Angel


conditional:

--op  <
    --courseconfirm(0)
    --0

**Meaning: If variable's value is less than one, return true

modifier to variable:

--op modify-variable
    |--courseconfirm(0)
    ---op +
        --- 1
        --- 0


**Meaning: Take variable, and add a value of 1 to it. Making it "1" and invalidating the conditional (above).

   
      Does this jive or no?
1) The red part has the wrong symbol.  Use = instead of < in the conditional.

2) The blue part is unnecessary.  Instead of using the + sexp, change the data type to a number, and enter 1.

As for the general validity of your code, it is a little bit hard to tell based on your description.  If the conditional of each event looks like this:
Code: [Select]

[b]and[/b]
  [b]=[/b]
    [b]courseconfirm(0)[/b]
    [b]0[/b]
  [b][/b]


Then yes, it will work.
« Last Edit: September 12, 2004, 03:57:38 am by 448 »
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

 
Quote
1) The blue part is unnecessary. Instead of using the + sexp, change the data type to a number, and enter 1.


    I don't quite follow here, I tried to "replace data" when fixed on the op + bit and it when I entered 1 it just moved me down a line. What do I press to get to where you're talking about.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Quote
Originally posted by Akalabeth Angel
Okay, for a mission I'm making (for FA academy). What I'm doing is I'm giving a ship several possible waypoint paths depending on the situation. So for each possibility, I have an event. But in order to ensure that other events aren't introduced after the first correct one I'm trying to use a variable.


I always get a special thrill when I see people using variables ;) Glad to see you're being brave and trying them out. They aren't really that hard but a lot of people are scared of them.

Quote
Originally posted by Akalabeth Angel
Basically, one of the conditions of the events going off is that a numeric variable has value < 1. Then when an event works, the value is supposed to be increased by 1 (from 0 to 1), therefore, invalidating the other events.


Sounds like a fair plan although I'm a little confused as to why you're using a variable for this rather than simply checking if the event is true or not.

Quote
Originally posted by Akalabeth Angel
I was just wondering if my code was cool:

conditional:

--op  <
    --courseconfirm(0)
    --0

**Meaning: If variable's value is less than one, return true


As Sesquipedalian said you can use the equals operator in this case.  The equals operator works perfectly well with variables because you can control what state the variable is in. The rest of the time you should always use the greater than and less than ops because it's possible for a value to skip the value your testing for (For instance  testing that damage to a ship =50% is a bad idea because some weapons can instantly take the damage from 51% to 49% without passing 50).
 There is nothing wrong with using the less than operator in this example though but if you wanted to do so your code would still be wrong as you're testing if the variable is less than 0 at the moment (maybe that was a typo though) :D

Quote
Originally posted by Akalabeth Angel
modifier to variable:

--op modify-variable
    |--courseconfirm(0)
    ---op +
        --- 1
        --- 0

**Meaning: Take variable, and add a value of 1 to it. Making it "1" and invalidating the conditional (above).


What you've done here would actually work in this mission. It's just a little pointless.
 What the event you've got here does is take the value 1. Add 0 to it (obviously pointless) and then assign that value to the variable (ignoring whatever the variables value was). In this case your event would work as the variable has a default value of 0 but if your variable started as 1 it's vaule would still be 1 at the end of it. Your event isn't actually refering to the value of the variable at any point. It's just assigning a value to it.

What Sesquipedalian has told you to do is to simply change the SEXP to

-modify-variable
--variablename (0)
--1

In this simple example this works perfectly and is all you need to do. But since the Academy is all about teaching FRED I may as well show you the code for adding one to a variable. You were actually on the right track.

--modify-variable
---courseconfirm(0)
----+
-----courseconfirm(0)
-----1

Notice the difference now? This time the value held in the courseconfirm variable is referenced. 1 is added to it and then the new value is assigned to the courseconfirm variable.
 

Quote
Originally posted by Akalabeth Angel
I don't quite follow here, I tried to "replace data" when fixed on the op + bit and it when I entered 1 it just moved me down a line. What do I press to get to where you're talking about.


Yeah. That's exactly what happened to me when I tried it just now so I don't think you did anything wrong. Just FRED being a little buggy. Just change the whole modify-variable SEXP into something else (do-nothing is an obvious choice) and then start again.
« Last Edit: September 12, 2004, 04:31:33 am by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Quote
Sounds like a fair plan although I'm a little confused as to why you're using a variable for this rather than simply checking if the event is true or not.


      Because the ship has four possible paths, so either I use one variable or three Sexps. Seems the first is the more efficient. I don't have time right now but I'll check it out in abit.

  

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Quote
Originally posted by Akalabeth Angel
Because the ship has four possible paths, so either I use one variable or three Sexps. Seems the first is the more efficient. I don't have time right now but I'll check it out in abit.


Aha. I thought you only had 2 possible values for the variable. If there are more then you're probably correct :D
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]