Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: multiple switch combinations  (Read 3528 times)

0 Members and 1 Guest are viewing this topic.

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
multiple switch combinations
« on: January 12, 2008, 09:52:34 PM »

Hey guys! I'm working on quite an aesthetic arty game which i'll announce soon =]
I've gotten a lot done by copying stuff from tuturials, i actually started last year. I'll save you all my confused attempts at scripting, since I have little coding experience I've gotten a lot of the basics done by searching the forum or modifying example games but its a bit hit and miss.

I want a scene which has multiple lights which can be turned on or off in any combination. I have prepared multiple images which take up the whole screen and show the lights turned on and off in all combinations; white light on + red light off, red and white light on together, all lights off etc. I tried using the code from the fan in the tutorial but got in a bit of a muddle plus i couldn't find how to display one outcome which was the product of two variables, ie. switching two light switches and showing the one image which has both lights on.

Essentially there is no background in the scene, just multiple versions of it and the ability to switch between them by pressing the switches on the individual lamps. I hope its not bad etiquette to ask without showing code I've tried, I feel a bit like im shopping in a foriegn country, do I attempt to speak their tongue or just ask in English! Cheers.

Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: multiple switch combinations
« Reply #1 on: January 13, 2008, 12:29:28 AM »

hi iain,

first of all you might want to check my online book which could help you on your path http://forum.dead-code.org/index.php?topic=2600.msg16700

without seeing your example it's very hard to help as there are many approaches. I'd map buttons to global variables or to global array and then switched the lights accordingly. I'd probably create an object which would take care of the light switching according to buttons pressed so I'd have it centralized.

Try to specify more what exactlu is the problem as I don't see clearly what are you missing.

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
Re: multiple switch combinations
« Reply #2 on: January 13, 2008, 02:34:22 PM »

Thanks metamorphium, the book is looking good, I've just been reading it and already learnt a few new tricks I didnt realise. I'm still struggling a bit with how i would use a global array here. This is what I have so far, I've managed to get one light to turn on and off (lightw which is a white light) and when i turn the red light on (lightr)the third image does appear with both lights on. However when I get to this point neither lights turn off and I'm stuck with the image with both lights on. Also when i turn the red light on individually i can not turn it off or switch to the white light image.

To clarify, the scene has 4 basic image sprites; one showing no lights on, one with the red light turned on, one with the white light on and one with both turned on. The image with no lights is the default and the only one which isn't hidden initially.

This is the code attatched to the white light switch named lightwregion

Code: [Select]
#include "scripts\base.inc"

actor.Active = false;
global Statelightdemo;

on "LeftClick"

  global EntLight = Scene.GetNode("light");
  global EntLightw = Scene.GetNode("lightw");
  global EntLightr = Scene.GetNode("lightr");
  global EntLightwr = Scene.GetNode("lightwr");

   if(Statelightdemo.lightwon==false)
   {
   EntLight.Active = false;
   EntLightr.Active = true;
   Statelightdemo.lightron = true;
   
}
else if(Statelightdemo.lightron==true)
   {
   EntLight.Active = true;
   EntLightr.Active = false;
   Statelightdemo.lighton = true;
   
}
else if(Statelightdemo.lightwon==true)
   {
   EntLightwr.Active = true;
   EntLight.Active = false;
  Statelightdemo.lightwron = true;
   
}
else if(Statelightdemo.lightwron==true)
   {
   EntLightwr.Active = false;
   EntLightw.Active = true;
   Statelightdemo.lightwon = true;
}
}

and this is the code attatched to the red switch

Code: [Select]
#include "scripts\base.inc"

actor.Active = false;
global Statelightdemo;
on "LeftClick"

  global EntLight = Scene.GetNode("light");
  global EntLightw = Scene.GetNode("lightw");
  global EntLightr = Scene.GetNode("lightr");
  global EntLightwr = Scene.GetNode("lightwr");

   if(Statelightdemo.lightwon==false)
   {
   EntLight.Active = false;
   EntLightr.Active = true;
   Statelightdemo.lightron = true;
   }

else if(Statelightdemo.lightron==true)
   {
   EntLight.Active = true;
   EntLightr.Active = false;
   Statelightdemo.lighton = true;
   }

else if(Statelightdemo.lightwon==true)
   {
   EntLightwr.Active = true;
   EntLight.Active = false;
   Statelightdemo.lightwron = true;
   
}
else if(Statelightdemo.lightwron==true)
   {
   EntLightwr.Active = false;
   EntLightw.Active = true;
   Statelightdemo.lightwon = true;
   }
}
Logged

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
Re: multiple switch combinations
« Reply #3 on: January 18, 2008, 07:10:35 PM »

ok im back and have simplified the code, hopefully it will be more clear what im trying to do although it doesnt work fully still.

This is the code attached to the white light region. lightw is the image with the white light on, lightr with the red on and lightwr has both on.

Code: [Select]
on "LeftClick"
{
  global EntLightw = Scene.GetNode("lightw");
  global EntLightr = Scene.GetNode("lightr");
  global EntLightwr = Scene.GetNode("lightwr");
 
if
    (EntLightw.Active==false)
{
EntLightw.Active=true;
}

if
    (EntLightw.Active==true)
{
EntLightw.Active=false;
}

if (EntLightr.Active==true)
     {
  EntLightwr.Active=true;
}

if (EntLightwr.Active==true)
     {
  EntLightwr.Active=false;
}
}

and this is for the red light region

Code: [Select]
on "LeftClick"
{
  global EntLightw = Scene.GetNode("lightw");
  global EntLightr = Scene.GetNode("lightr");
  global EntLightwr = Scene.GetNode("lightwr");
 
if
    (EntLightr.Active==false)
{
EntLightr.Active=true;
}

if
    (EntLightr.Active==true)
{
EntLightr.Active=false;
}

if (EntLightw.Active==true)
     {
  EntLightwr.Active=true;
}

if (EntLightwr.Active==true)
     {
  EntLightwr.Active=false;
}
}

The entities are layered so that lightwr is on top so i dont have to bother turning the individual lights off and on again. I'm still finding that once  lightwr gets displayed  i can not get back to the lightr or lightw. The code I thought would deal with this is:

Code: [Select]
if (EntLightwr.Active==true)
     {
  EntLightwr.Active=false;
}

Thereby hiding this top layer and displaying whichever individual light is left active below it. But this doesnt happen, nothing does from this point. I'm also puzzled why I can only get lightwr to display if i "switch" the light on in the order of lightw and then lightr. Thanks, I'll be thankful if anyone can help!
Logged

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
Re: multiple switch combinations
« Reply #4 on: February 02, 2008, 03:00:35 AM »

Finally! I figured it out, it all about the layers which is something I hadnt used much until now. I started from scratch and put each sprite entity in a seperate close-up layer instead of multiple sprite entities in one layer. I'm not sure why my old way didn't work but this way the scripts are simpler although there are more of them. Now each layer has seperate light switch regions/scripts which simply turns on a certain layer depending on which what lights are already on or off.
Here's the scene if anyones interested, its just a test so the image isnt that clear. One switch is above the headphones and the other is at the base of the lamp to the right of the monitor.
http://ichatburn.co.uk/stuff/lights.zip
Logged
 

Page created in 0.034 seconds with 23 queries.