Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Marcusqc on June 08, 2010, 09:12:07 am

Title: testting variable whit loop
Post by: Marcusqc on June 08, 2010, 09:12:07 am
hi,
i want to test a elaborate variable system . and to do so i have make looping freed over a key pressed expample :

Code: [Select]
$Formula: ( when
   ( key-pressed "Shift-C" )
   ( training-msg "variable show" )
)
+Name: show variable
+Repeat Count: 999
+Trigger Count: 999
+Interval: 1
+Team: 8484

$Formula: ( when
   ( key-pressed "Up Arrow" )
   ( modify-variable
      @X[0]
      ( + @X[0] 50 )
   )
)
+Name: test variable up
+Repeat Count: 1
+Trigger Count: 999
+Interval: 20
+Team: 16733525

$Formula: ( when
   ( key-pressed "Down Arrow" )
   ( modify-variable
      @X[0]
      ( - @X[0] 50 )
   )
)
+Name: test variable down
+Repeat Count: 1
+Trigger Count: 999
+Interval: 20
+Team: 2081

the problem is that the variable just keep incressed over time and i just whant it to increasse when i puch up or down.
I just whant to be able to control the variable whit a key presse for make some test

thank for your help



Title: Re: testting variable whit loop
Post by: The E on June 08, 2010, 09:23:08 am
You need to use the key-reset sexp. Like this:

( when
   ( key-pressed "Up Arrow" )
   ( modify-variable
      @X[0]
      ( + @X[0] 50 )
   )
   ( key-reset "Up Arrow" )
)
Title: Re: testting variable whit loop
Post by: Marcusqc on June 08, 2010, 09:46:24 am
is work but if i want to change the way ex: i have 200 or -200 to a positive or negative , value it get stuck and nothing change.
I run some test that i have 200 and what to drop it to 100 and i get stuck to 200, i'm not even able to go to  250 or 300.
Title: Re: testting variable whit loop
Post by: The E on June 08, 2010, 10:01:08 am
I am truly sorry, but I have trouble understanding that. What's your native language?
Title: Re: testting variable whit loop
Post by: Marcusqc on June 08, 2010, 10:16:18 am
lol french .. OK i will try to explain in a different way... it work .. i mean that went i press up or down the variable change ... but i can only go positive or negative, if i what to change, the variable get stuck... ex: i go up to 200 then i what to go down to 100, well the variable will get stuck to 200 what ever I'm doing( press up or down nothing change i have to reset the mission)

i hope this new syntax will help i still learn the grammar and punctuation
Title: Re: testting variable whit loop
Post by: MatthTheGeek on June 08, 2010, 10:23:04 am
Ok, can you tell again it in French ? I'll handle the translation.

Ok, peux-tu nous la refaire en français ? Je vais me charger de la traduction.
Title: Re: testting variable whit loop
Post by: Marcusqc on June 08, 2010, 10:35:14 am
sa fonctionne,  je peux aller en positif ou négatif mais  juste dans un sense . Example si je vais à 200 et que je veux aller à 100 (ou linverse -200 à -100) tout bloque .Je doit redémarré la mission pour changer la variable  nouveau. donc en résumé si je press up je peux que augmenter ma variable car si je press down ( ou up, depend of the firts key press)  tout bloque et je ne peux pas changer ma variable any more

(it's hard to tanslate in English because when i'm coding i thinks in English lol)
Title: Re: testting variable whit loop
Post by: MatthTheGeek on June 08, 2010, 10:41:09 am
Alright, the problem seems to be that once he start to increase the variable (from 0 to 200 for example), he can only increase it and can't decrease it anymore (from 200 to 100 for example) without restarting the editor.
Title: Re: testting variable whit loop
Post by: Marcusqc on June 08, 2010, 10:56:19 am
Alright, the problem seems to be that once he start to increase the variable (from 0 to 200 for example), he can only increase it and can't decrease it anymore (from 200 to 100 for example) without restarting the editor.
same thing for negative (from 0 to -200 )
Title: Re: testting variable whit loop
Post by: karajorma on June 08, 2010, 11:01:24 am
Hardly surprising if you're using key-reset rather than key-reset-multiple.

You should also be warned that the output of the key-pressed SEXPs in loops is determined by the type of key it is. Keys like T, H and F which are assigned to "Press once for each change" style commands work differently from keys like A or Z which you hold down to continually have an effect so you may wish to swap the up and down keys to something like T, H or F for this test.
Title: Re: testting variable whit loop
Post by: Marcusqc on June 08, 2010, 11:33:50 am
thank you master karajorma , T and H whit key-reset-multiple work great (up or  down dose nothing  so i asume there are like a or z in the coding)