GoPinball.com
http://www.gopinball.com/forum/

VBS Help : for LOOP and If statement?
http://www.gopinball.com/forum/viewtopic.php?f=14&t=5400
Page 1 of 1

Author:  HappyCab [ Tue May 12, 2015 10:09 pm ]
Post subject:  VBS Help : for LOOP and If statement?

I know how to do in in flash action script but can't wrap my head around if it is even possible in FP VBS.

I have 10 elements. they are all nicely set (variable, states and pf position) with a for loop :

Code:
Sub DropAllBaddies()
   dim x
      for x=1 to 11
         Execute"ST"&x&".MoveTo ST"&x&".tx, -30, ST"&x&".tz ,500"
         Execute "insert"&x&".frame 1"
         Execute "DT"&x&".PopDown"
      next
end sub


But the thing is that I need it to happen ONLY if a condition is met :

Roughly-------------------------------
Code:
for x=1 to 11
if (ST[x].isDead=false )then......



How would it be written to work in VBS?

Author:  Wecoc [ Wed May 13, 2015 2:34 pm ]
Post subject:  Re: VBS Help : for LOOP and If statement?

Did you tried with Eval?

Code:
Sub DropAllBaddies()
   Dim x
   For x = 1 to 11
      If Eval("ST" & x).isDead = false Then
         Execute "ST" & x & ".MoveTo ST" & x & ".tx, -30, ST" & x & ".tz ,500"
         Execute "insert" & x & ".frame 1"
         Execute "DT" & x & ".PopDown"
      End If
   Next
End Sub


Eval works similar than Execute, and I'm not completely sure about the differences.

As a side note, I prefer to use Eval because I think it's cleaner this:

Eval("DT" & x).PopDown

Than this:

Execute "DT" & x & ".PopDown"

Only the variable part has to be an string inside the eval.

And so, I reserve the Execute when the full method depends on a String, which is so unusual (I used that on the Multi-Light demo, assigning methods as strings into the Hash)

It would be:

Code:
Sub DropAllBaddies()
   Dim i : For i = 1 to 11
      If Eval("ST" & i).isDead = false Then
         Dim x, z
         x = Eval("ST" & i).tx : z = Eval("ST" & i).tz
         Eval("ST" & i).MoveTo x, -30, z, 500
         Eval("insert" & i).frame 1
         Eval("DT" & i).PopDown
      End If
   Next
End Sub


But both ways are viable.

Author:  HappyCab [ Wed May 13, 2015 2:51 pm ]
Post subject:  Re: VBS Help : for LOOP and If statement?

didn't know eval could be mixed within an if statement but that make sens. will test it tonight thx a lot wecoc

Author:  HappyCab [ Thu May 14, 2015 6:45 am ]
Post subject:  Re: VBS Help : for LOOP and If statement?

actually the eval look strangely a lot more flash actionscript 2 which is great!

your line : Eval("DT" & x).PopDown
in flash AS2 : this["DT" + x].PopDown

Author:  HappyCab [ Thu May 14, 2015 11:16 pm ]
Post subject:  Re: VBS Help : for LOOP and If statement?

worked like a charm, thx a lot!

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/