Author Topic: Question about variables  (Read 3053 times)

0 Members and 1 Guest are viewing this topic.

Question about variables
Ok, y'know how variable-changing SEXPs say
Code: [Select]
1. Variable to be changed
2. value to be set

does that mean it will be set to that value, or it will be changed by that value?
Sig nuked! New one coming soon!

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Question about variables
It will be set to that value. If you want to change by that value use

Modify-Variable
-Variable-Name
-+ (Or -, multiply, divide or whatever)
--Variable-Name
--Value

For instance this is a classic +1 counter.

Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Snail

  • SC 5
  • 214
  • Posts: ☂
Re: Question about variables
Had one question. Could it be possible in the next build to have number variables to be "transplanted" into string variables? So if I had a ship named "Counter" with an Alt Name "0", and when something happens (like you destroy an enemy cruiser), the number variable goes to 1, which is copied to a string variable, which becomes the Alt Name of the ship "Counter?" (so whenever you destroy one of the specified cruisers, the ship Counter's Alt Name goes up by one)

Or is this already possible and I'm just too stupid to see?

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Question about variables
It's not possible but IP Andrews has been asking for something of the sort for a while now. The problem is that it requires a proper String return type which the SEXP system currently doesn't support.

I think Goober and myself are going to have to play rock, paper, scissors one of these days over who has to do it. :D
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Question about variables
I have an idea about how to add proper data type support to sexps, but it would involve about as much work as when-argument did.  Since I don't have that much time nowadays, I'm hesitant to jump in. :D

 
Re: Question about variables
Thanks Mobius!  :D

Had one question. Could it be possible in the next build to have number variables to be "transplanted" into string variables? So if I had a ship named "Counter" with an Alt Name "0", and when something happens (like you destroy an enemy cruiser), the number variable goes to 1, which is copied to a string variable, which becomes the Alt Name of the ship "Counter?" (so whenever you destroy one of the specified cruisers, the ship Counter's Alt Name goes up by one)

Or is this already possible and I'm just too stupid to see?

why would you wanna do that? or can you not even answer because it would destroy plot? :D
Sig nuked! New one coming soon!

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Question about variables
I have an idea about how to add proper data type support to sexps, but it would involve about as much work as when-argument did.  Since I don't have that much time nowadays, I'm hesitant to jump in. :D

How long did it take you to do that out of interest?
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Question about variables
I honestly don't remember.  But it was a solid weekend of coding, plus a few miscellaneous bugfixes after the initial commit.

I just realized though, Snail's request doesn't require special handling of data types, strictly speaking.  All it needs is a copy-number-to-string-variable sexp, and (if necessary) an extension of change-alt-name to work for string variables.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Question about variables
Yeah but that strikes me as something of a hack. If someone wants to stick a number in a change-alt-name SEXP they should be able to do it without the need for an intermediate SEXP variable. All it should require is a reverse of the atoi SEXP I added.


Actually now that I think of it, it should be possible to do this without any changes. Use a repeated when-argument event using the in-sequence option (I knew I'd find uses for it once I added it! :D ). Here's how I'd do it for 4 ships.

when-argument
-in-sequence
--Two
--Three
--Four
-percentage-ships-destroyed
--TargetPercentage[25]
--Names of all 4 freighters
-Modify-variable
--TargetPercentage[25]
-- +
----TargetPercentage[25]
---- 25
-change-alt-name
--ShipName
--<Argument>
-invalidate argument

Give that a repeat count of 3.

Every time a ship is destroyed the percentage needed to trigger the event is bumped by 25% and the alt-name is changed to the next one on the list. You could probably use numbers instead of the written version I've used, I've not checked.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Question about variables
Cool. :)

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Question about variables
Problem with having the SCP is that makes me lazy. When all I had was retail I'd have spent 10-15 minutes thinking my way around a problem like that but now I simply say it's not possible yet and say that code changes are needed. :D
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 
Re: Question about variables
beats being a whiny noob like me...
Sig nuked! New one coming soon!

 

Offline Snail

  • SC 5
  • 214
  • Posts: ☂
Re: Question about variables
I'm amazed at how basically everything I've thought up of is already possible... Good jawb. :yes: