Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Snoop key function  (Read 6181 times)

0 Members and 1 Guest are viewing this topic.

FogGobbler

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 228
    • View Profile
Snoop key function
« on: February 28, 2007, 02:55:47 PM »

Hi!

Is it possible to program a function that shows all the hotspots in a scene (like in "Geheimakte Tunguska"), when the player presses a certain key and could anbody offer me some kind of code-bits or ideas to get me started?

Thanks,
Oli
Logged

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Snoop key function
« Reply #1 on: February 28, 2007, 03:23:58 PM »

Hi,

I just added such a function to our game and it works nice.

First of all add a global variable to your base.inc:

Code: [Select]
global ShowHotspots;
Then add the following to your game.script:

Code: [Select]
on "Keypress"
{
   // on Space key
  if(Keyboard.KeyCode==VK_SPACE)
  {
    if(!ShowHotspots) {
      // load and display the main menu window
      if(Scene.Name!="Startmenu" && Scene.Name!="LeereSzene" && Scene.Name!="Credits" && Scene.Name!="Logo" && !Game.ChangingScene) {  // This is just for excluding some scenes in the game where hotspots shouldn't be shown
         var MainLayer = Scene.MainLayer;
         var Helper=new Array(MainLayer.NumNodes);

         ShowHotspots=true;

         // process all entities in the main scene layer
         for(var i=0; i<MainLayer.NumNodes; i=i+1) {
            var Node = MainLayer.GetNode(i);
            if(Node.Type=="entity" && Node.Interactive==true && Node.Active==true) {
                  Helper[i]=Scene.CreateEntity("Helper");
                  var HelperHelp=Helper[i];
                  HelperHelp.SetSprite("sprites\system\help.sprite");   // Replace this with a sprite that should mark the hotspots
                  HelperHelp.X=Node.X;
                  HelperHelp.Y=Node.Y-(Node.Height/2);
                  HelperHelp.Active=true;
                  HelperHelp.Interactive=false;
                  HelperHelp.Scalable=false;
                  HelperHelp.Rotatable=true;
            }
         }

         // rotate all helper entities
         for(var t=0; t<=360; t=t+15) {
           for(i=0; i<MainLayer.NumNodes; i=i+1) {
              HelperHelp = Helper[i];
              if(HelperHelp.Name=="Helper") {
                    HelperHelp.Rotate=t;
              }
           }
           Sleep(50);
         }

         // delete all helper entities
         for(i=0; i<MainLayer.NumNodes; i=i+1) {
            HelperHelp = Helper[i];
            if(HelperHelp.Name=="Helper") {
                  Scene.DeleteEntity(Helper[i]);
            }
         }

         ShowHotspots=false;

      }
    }
  }

}

It shows sprites on every (active) hotspot (in our case a little question mark) in the scene when hitting the space key and rotates it 360 degrees.
You may change it the way you want it, but maybe this helps you to get in the right direction.

Mac
Logged

FogGobbler

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 228
    • View Profile
Re: Snoop key function
« Reply #2 on: February 28, 2007, 03:28:23 PM »

Wow! Thanks a lot for the quick reply and for sharing your code  :)
  I´ll give it a try ..
Logged

FogGobbler

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 228
    • View Profile
Re: Snoop key function
« Reply #3 on: February 28, 2007, 10:49:24 PM »

Hi, Mac!

Well I tried it with the standard 3d-demo, but it didn´t work. I changed the sprite and the layer, because it is called "main" in the demo.

I really can´t find any error in the script, but it seems that it doesn´t find any entities. Can you (or anybody else) please help?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Snoop key function
« Reply #4 on: February 28, 2007, 11:01:48 PM »

I tried it in 3d demo and it DID work. I only used a different sprite. What to you mean you changed the layer?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
Re: Snoop key function
« Reply #5 on: February 28, 2007, 11:51:43 PM »

i tried it in my own project ... works funtastic !!!!
excelent piece of code ...
do you mind if i use it in Schach-Welten / Chess-Worlds ??

Greets stucki

FogGobbler

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 228
    • View Profile
Re: Snoop key function
« Reply #6 on: March 01, 2007, 01:24:59 AM »

Great, I got it to work  :) .

It doesn´t seem to run in windowed-mode, that was the problem I had.

I would also like to use it in our project, please.

Greets, Oli
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Snoop key function
« Reply #7 on: March 01, 2007, 08:43:59 AM »

Note that the code won't work in 100% cases. Depending on scene layout sometimes the help icons could be hidden behind some scene entities. A cleaner (but less generic) solution would be to add a special region to the scene. The region would be all the way down in the node list, and the script would stick the help icons to this region (using the StickToRegion() method). It would assure that the help icons are always on top.
Secondly, the script only iterates through scene entities. If you loaded an entity dynamically at runtime, it wouldn't get the help icon. WME now provides a way of iterating these "free" entities, using Scene.NumFreeNodes and Scene.GetFreeNode().
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Snoop key function
« Reply #8 on: March 03, 2007, 12:02:40 AM »

Hi,

of course everybody may feel free to use the code and to do with it what he wants.

@Mnemonic:
Is there a way to create a region at runtime? It would be a lot of work to add it to each scene manually in scene edit.

Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Snoop key function
« Reply #9 on: March 03, 2007, 10:03:35 AM »

Is there a way to create a region at runtime? It would be a lot of work to add it to each scene manually in scene edit.
Unfortunately it's not possible at the moment. I'll need to add something like Layer.CreateEntity() / Layer.CreateRegion(). There must be means of setting the right position within the node list somehow, though.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Snoop key function
« Reply #10 on: March 03, 2007, 03:15:40 PM »

I added new Scene methods for dynamic layer creation. So now the hint icons can reside in their own top-level layer, which is near to perfect (I think :)) I'll post the updated script once WME 1.7.2 is out.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Snoop key function
« Reply #11 on: March 04, 2007, 12:30:18 PM »

That's very cool!  ::rock
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Snoop key function
« Reply #12 on: March 11, 2007, 06:30:56 PM »

And as I promised, I posted the updated code in WME Wiki.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.036 seconds with 19 queries.