Hi
Is it possible to have 2 dimensional arrays in visual pinball, similar to vb net? For example an array of numbers, which can then referenced.
1,2,3,4,5
6,7,8,9,0
5,4,3,2,1
0,9,8,7,6
If it is possible, sample code would be great.
Regards - Mike
Posted 26 December 2012 - 11:24 AM
Like this,
'Declare the array' Dim testarray (4,5) 'Fill in the values' testarray (1,1)=1 : testarray (1,2)=2 ' ...
Or declare and assign values in one go,
testarray = Array(Array(1,2,3,4,5),Array(6,7,8,9,0),Array(5,4,3,2,1),Array(0,9,8,7,6))
This will create the 2d array example in your post.
Edited by rosve, 26 December 2012 - 11:25 AM.
Posted 26 December 2012 - 01:43 PM
so not knowing a whole hell of a lot about coding
what are arrays and why would they be needed in vp?
we use 'collections' to call out a bunch of items to do something
at the same time is that the same thing as an array?
Edited by faralos, 26 December 2012 - 01:44 PM.
Posted 26 December 2012 - 09:25 PM
Hi
A good example of an array in VP is JP’s alpha plunger routine. It’s a single dimension array. VP collections are a good way to thinking of arrays.
Another way is to imagine a DVD collection. If you want a certain DVD you’d need to start with the first one in the collection and look through them individually until you find the one you want.
You'd probably use an if statement e.g. is Ted = Lawless, is Elf = Lawless, etc. until you find Lawless = Lawless.
Ted, Elf, Flight, Lawless, Looper, xXx, etc
In a 2 dimensional array if you’re looking for that DVD you can go directly to it. It saves time – in programming it means efficiency.
With the DVD example, if you’re looking Lawless, you can go directly to it (Drama, Lawless).
Genre Title
Comedy Ted, Elf, etc
Drama Flight, Lawless, etc
Action Looper, xXx, etc
There are people on this forum that can probably explain it better. Hope this helps?
Regards - Mike
Posted 26 December 2012 - 09:31 PM
that's a pretty fair explanation and as far as i know also not possible within the vp editor
hence our use of if then statements within the coding
but it sounds like a cool concept if it can be put into the vp program
Posted 27 December 2012 - 08:07 AM
Hello rosve
I need a syntax check please. Using:
Dim testarray:testarray = Array(Array(1,2,3,4,5),Array(6,7,8,9,0),Array(5,4,3,2,1),Array(0,9,8,7,6))
For i = 1 to 4
For j = 1 to 5
if testarray(i, j) = 4 then ....
Next
Next
I get "subscript out of range testArray" error on runtime - complies fine. changing the i and/or j value has no affect.
Thanks - Mike
Posted 27 December 2012 - 09:50 AM
that's a pretty fair explanation and as far as i know also not possible within the vp editor
hence our use of if then statements within the coding
but it sounds like a cool concept if it can be put into the vp program
It's not an "editor thing" but a "scripting thing" & therefore can be done (as already explained in this thread).
Another analogy to use might be how to store all the information for a league table - let's say you have 20 teams and you want to know the games played, won, drawn, lost, points for, points against, league points - i.e. 6 pieces of information for each of the 20 teams it would make sense to have a 2D array (20,6) - 20 lines with 6 pieces of info in each line. You can then reference the piece you want with a single coordinate - e.g. to find the games lost by the 10th team look-up the value at (10,4).
You can read/write info into it using loops
e.g.
For i = 0 to 19
For j = 0 to 5
'Read/write info here at (i,j) in the array
'set i & j as require depending on what you're trying to achieve
Next
Next
The 2D array can just be pure information (variables, text etc) or it can refer to other arrays (collections etc).
Basically using 2D arrays *can* cut down on your scripting a lot if you know what you're doing with them (Faralos....leave them alone
)
Hope this makes sense.
Regards,
Dan.
Posted 27 December 2012 - 09:56 AM
Hello rosve
I need a syntax check please. Using:
Dim testarray:testarray = Array(Array(1,2,3,4,5),Array(6,7,8,9,0),Array(5,4,3,2,1),Array(0,9,8,7,6))
For i = 1 to 4
For j = 1 to 5
if testarray(i, j) = 4 then ....
Next
Next
I get "subscript out of range testArray" error on runtime - complies fine. changing the i and/or j value has no affect.
Thanks - Mike
I had to check this again,
It looks like the Array function is not implemented correctly in the VP version of VBS.
You have to use the "hard" way of assigning values one by one.
Dim testarray (4,5) testarray (1,1)=1 : testarray (1,2)=2 : ... testarray (2,1)=1 : testarray (2,2)=2 : ...
Edited by rosve, 27 December 2012 - 10:31 AM.
Posted 27 December 2012 - 10:13 AM
The issue is with how you've declared your arrays.
I could be wrong, but setting them up needs to be a little bit more labour intensive (& the first element in an array is 0).
e.g. using your numbers from above, you'd need to set up something like this:
Dim DansArray(4,5)
Dim Dan1(5):Dan1(0)=1:Dan1(1)=2:Dan1(2)=3:Dan1(3)=4:Dan1(4)=5
Dim Dan2(5):Dan2(0)=6:Dan2(1)=7:Dan2(2)=8:Dan2(3)=9:Dan1(4)=0
Dim Dan3(5):Dan3(0)=5:Dan3(1)=4:Dan3(2)=3:Dan3(3)=2:Dan1(4)=1
Dim Dan4(5):Dan4(0)=0:Dan4(1)=9:Dan4(2)=8:Dan4(3)=7:Dan1(4)=6
For i=0 to 4
DansArray(0,i)=Dan1(i)
DansArray(1,i)=Dan2(i)
DansArray(2,i)=Dan3(i)
DansArray(3,i)=Dan4(i)
Next
Sub Table1_KeyDown(ByVal keycode)
If keycode=32 then
For i=0 to 3
For j=0 to 4
If DansArray(i,j)=4 then
ScoreText.Text=ScoreText.Text & "("&i&","&j&")"
End if
Next
Next
End If
End Sub
Hope this helps.
Regards,
Dan.
Posted 27 December 2012 - 10:44 AM
You don't need to make all the extra arrays for the second index.
Dim DansArray(3,4)
DansArray(0,0)=0:DansArray(0,1)=1:DansArray(0,2)=2:DansArray(0,3)=3:DansArray(0,4)=4
DansArray(1,0)=6:DansArray(1,1)=7:DansArray(1,2)=8:DansArray(1,3)=9:DansArray(1,4)=0
DansArray(2,0)=5:DansArray(2,1)=4:DansArray(2,2)=3:DansArray(2,3)=2:DansArray(2,4)=1
DansArray(3,0)=0:DansArray(3,1)=9:DansArray(3,2)=8:DansArray(3,3)=7:DansArray(3,4)=6
Sub Table1_KeyDown(ByVal keycode)
If keycode=32 then
For i=0 to 3
For j=0 to 4
If DansArray(i,j)=4 then
ScoreText.Text=ScoreText.Text & "("&i&","&j&")"
End if
Next
Next
End If
End Sub
Posted 27 December 2012 - 10:47 AM
Yeah, I recognise that.
I was assuming that as mbusetti had used different sub-arrays that he wanted to use sub arrays in his 2D array, so I included them in my example.
Regards,
Dan.
Edited by Wizards_Hat, 27 December 2012 - 10:48 AM.
Posted 27 December 2012 - 11:06 AM
Thanks guys
Hopefully the next version on VP will have the 'easy' way implemented for declaring arrays!
Looks like I've got a lot of typing to do (which always means typo mistakes for me)
Thanks again.
No worries.
I think the implementation in script is more to do with VB scripting than anything VP related - so you'll not see any differences unless Microsoft update VB scripting (don't hold your breath there!).
As for typo's...always use "option explicit" as the first line of your code...though that'll not help you if you mistype a number in an array! ![]()
Regards,
Dan.
Posted 27 December 2012 - 11:39 AM
You don't need to make all the extra arrays for the second index.
Dim DansArray(3,4) DansArray(0,0)=0:DansArray(0,1)=1:DansArray(0,2)=2:DansArray(0,3)=3:DansArray(0,4)=4 DansArray(1,0)=6:DansArray(1,1)=7:DansArray(1,2)=8:DansArray(1,3)=9:DansArray(1,4)=0 DansArray(2,0)=5:DansArray(2,1)=4:DansArray(2,2)=3:DansArray(2,3)=2:DansArray(2,4)=1 DansArray(3,0)=0:DansArray(3,1)=9:DansArray(3,2)=8:DansArray(3,3)=7:DansArray(3,4)=6 Sub Table1_KeyDown(ByVal keycode) If keycode=32 then For i=0 to 3 For j=0 to 4 If DansArray(i,j)=4 then ScoreText.Text=ScoreText.Text & "("&i&","&j&")" End if Next Next End If End Sub
Just wanted to confirm that using the concept above works for me. Thanks again.
Mike
Posted 27 December 2012 - 12:45 PM
Don't worry Dan all that is so Greek to me anyways
I can't begin to fathom what you guys are discussing!
this is why I flunked in school even with all those explanations I am still quite lost ![]()
but harking back to that 'Option Explicit' line
it has helped me so much in the past when writing out code
it will state even if you miss a comma somewhere or put it in the wrong place
it helps when play testing or compiling the code from a pin
even something as simple as a drop target that won't drop
it may show up as a 'null' error (if it has not been marked to drop in the editor)
without Option Explicit it could take me days to find such an error on my own
Posted 28 December 2012 - 12:28 AM
One more question guys
Is this possible? I can't seem to get it to work(not sure if it's possible?)
Dim Got1, Got2, Got3, Got4
Dim number(4)
Dim i
Got2 = True
For i = 0 to 3
If "Got"<rim(i+1) = True then number(i) = i+1
Next
Is it possible to compare a string to the variable name?
Regards - Mike
Visual Pinball →
Visual Pinball →
Detecting Uninitialized UserValueStarted by Two , 08 May 2025 |
|
||
Visual Pinball Development →
General Chat →
How to program multiball for custom VPX tables?Started by purpmctaxi , 07 Feb 2025 |
|
||
Visual Pinball →
Visual Pinball →
Set DOF Intensity using Table Script?Started by Ltek , 04 Jun 2024 |
|
||
Visual Pinball →
Visual Pinball →
Let's fix PizzaTime!Started by gamerplayer861 , 13 Mar 2024 |
|
||
Visual Pinball →
VP Help Center →
How to change a drop targets state in scriptStarted by Jackmc7r , 12 Mar 2024 |
|