Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Self switches help

wlzza

Sponsor

Hi there just wondering how I could incorporate arrays to self switches. I'm noob at scripting.

Code:
for k in 1...5
if $game_self_switches[[2, $game_map.events[k], 'A']] == true
  do this
else
  do that
end
end

What have I done wrong?
 

wlzza

Sponsor

Sorry. I have lots of events on the map and what I'm trying to do is that I need a way to check if these events have self switch A on or off. Having that many events I assume using arrays would be the best way. The problem is, I'm having difficulties in getting it to work.
 
The syntax to check Self Switches is $game_self_switches[map_id, event_id, switch]

map_id is the id of the map in which your event is
event_id is the id of the event you want to test
switch is "A","B","C" or "D"

In your case
Code:
for i in 1...5
  if $game_self_switches[2, k, 'A']
    your code 1
  else
    your code 2
  end
end
 

wlzza

Sponsor

I've tried that but got errors. Not just the i and the k.

I even tried:

Code:
for k in 1...5
  if $game_self_switches[[2, k, 'A']] == true
    code 1
  else
    code 2
  end
end
 

wlzza

Sponsor

I know, that's the problem single or double square brackets it doesn't work. In VX if you use $game_self_switches[2, k, 'A'] i get this error "wrong number of arguments (3 for 1)". While if I use $game_self_switches[[2, k, 'A']] it doesn't do anything.

When I use a fixed variable such as $game_self_switches[[2, 2, 'A']] it works but defeats my purpose.

I appreciate your help Dargor.
 
Oh, I'm sorry, you were right, it requires an array. I worked with self_switches only once a while ago.
I did it that way:
key = [map_id, event_id, switch]
if $game_self_switches[key]
...

and I have tested your method:
for i in 1..5
  p $game_self_switches[[1,i,'A']]
end
And it works fine. It prints 5 false.
 
One VERY easy thing to overlook....

Code:
$game_map.needs_refresh = true

So, when its "Doing nothing", yes the switch most likely had changed in the event yet the event's graphic/behavoir doesn't change without that line. At least thats how it works in XP, VX might be different but I think its the same in this case.
 
I think it works the same in VX. Correct me if I'm wrong, but, your goal was to test if a self-switch is on/off, right?
If you wanted to turn a self-switch on/off, then you will need to do as Kain told and add

$game_map.needs_refresh = true

After you change your self-swith.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top