| View previous topic :: View next topic |
| Author |
Message |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Dec 10, 2007 5:29 pm Post subject: [VB6] SetVariable - Multiple Variables |
|
|
Is there an easier way to set array variables other than typing them out?
For example, I have a game and the variable is:
| Code: | _root._game.towerArray.0.damage
_root._game.towerArray.1.damage
_root._game.towerArray.2.damage
_root._game.towerArray.3.damage
_root._game.towerArray.4.damage |
The number after "towerArray." is the tower number, so pretend I want it to set it all the way to 100, is there a faster way then typing it all out?
I was thinking you could add a "+ 1" somewhere so it could keep increasing. _________________
|
|
| Back to top |
|
 |
Devilizer Master Cheater
Reputation: 0
Joined: 22 Jun 2007 Posts: 451
|
Posted: Mon Dec 10, 2007 5:35 pm Post subject: |
|
|
| Use a timer..? |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Dec 10, 2007 5:38 pm Post subject: |
|
|
| Devilizer wrote: | | Use a timer..? |
Of course I know to use a timer, I need to know how you would do it though _________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Dec 10, 2007 5:38 pm Post subject: |
|
|
You could do something like:
| Code: | Private Function SetVariableArray(arrStart As Long, arrEnd As Long, arrValue As String)
Dim x As Long
For x = arrStart To arrEnd
FlashObject.SetVariable "_root._game.towerArray." & x & ".damage", arrValue
Next x
End Function |
Or create a function with a parser to look for a given character to change with the number to make it work for basically any variable you sent to it to make it more "dynamic". _________________
- Retired. |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Dec 10, 2007 5:39 pm Post subject: |
|
|
| Wiccaan wrote: | You could do something like:
| Code: | Private Function SetVariableArray(arrStart As Long, arrEnd As Long, arrValue As String)
Dim x As Long
For x = arrStart To arrEnd
FlashObject.SetVariable "_root._game.towerArray." & x & ".damage", arrValue
Next x
End Function |
Or create a function with a parser to look for a given character to change with the number to make it work for basically any variable you sent to it to make it more "dynamic". |
Ok I'll try it
EDIT: It says argument not optional
I don't really do modules, so I don't know if I'm doing something wrong
EDIT: Nvm, I fixed it, although it doesn't do anything
The code I'm using:
| Code: | Dim x As Long
arrStart = 0
arrEnd = 300
For x = arrStart To arrEnd
frmMain.flash1.SetVariable "_root._game.towerArray." & x & ".damage", txtDamage.Text
Next x |
EDIT AGAIN: Ok, lol, I forgot to put the quotes
Thanks for helping me, +rep  _________________
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Mon Dec 10, 2007 6:49 pm Post subject: |
|
|
Use a variable instead of hardcoding the 0, 1, 2, 3, 4, etc.
In Delphi it would be like:
| Code: |
procedure xxxxxxxxx([i]parameters...[/i])
var
i: Integer = 0
begin
repeat
begin
_root._game.towerArray.i.damage
// statements go here
Inc(i);
end;
until
i >= 100 // whatever max it is
end;
|
In VB, it would be different but you get the idea. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Dec 10, 2007 7:31 pm Post subject: |
|
|
| Blader wrote: | | Wiccaan wrote: | You could do something like:
| Code: | Private Function SetVariableArray(arrStart As Long, arrEnd As Long, arrValue As String)
Dim x As Long
For x = arrStart To arrEnd
FlashObject.SetVariable "_root._game.towerArray." & x & ".damage", arrValue
Next x
End Function |
Or create a function with a parser to look for a given character to change with the number to make it work for basically any variable you sent to it to make it more "dynamic". |
Ok I'll try it
EDIT: It says argument not optional
I don't really do modules, so I don't know if I'm doing something wrong
EDIT: Nvm, I fixed it, although it doesn't do anything
The code I'm using:
| Code: | Dim x As Long
arrStart = 0
arrEnd = 300
For x = arrStart To arrEnd
frmMain.flash1.SetVariable "_root._game.towerArray." & x & ".damage", txtDamage.Text
Next x |
EDIT AGAIN: Ok, lol, I forgot to put the quotes
Thanks for helping me, +rep  |
You got argument not optional because you forgot to pass one of the arguments when calling the function.
A proper call would be something like:
| Code: | | Call SetVariableArray( 0, 4, "100" ) |
Meaning the array starts at 0, ends at 4, and you want all the values to be 100. _________________
- Retired. |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Dec 10, 2007 7:33 pm Post subject: |
|
|
Yea, I forgot to set the strings
It's resolved now so no worries  _________________
|
|
| Back to top |
|
 |
|