Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Can somebody help me improve my code?  (Read 5364 times)

0 Members and 1 Guest are viewing this topic.

revvin

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 36
    • View Profile
Can somebody help me improve my code?
« on: April 01, 2005, 11:51:15 PM »

Code: [Select]
#include "scripts\base.inc"
global WinNarrator;
global entry_attempts=0;

var RowA = new Array ("A1.png","A2.png","A3.png","A4.png","A5.png","A6.png","A7.png","A8.png","A9.png","A10.png","A11.png","A12.png","A13.png","A14.png","A15.png");
var RowB = new Array ("B1.png","B2.png","B3.png","B4.png","B5.png","B6.png","B7.png","B8.png","B9.png","B10.png","B11.png","B12.png","B13.png","B14.png","B15.png");
var Locations = new Array ("Antigua","Barbados","Jamaica","Montserat","Nebraska","St. Kitts","Tortuga");
var wheelpos = Random (1,15); 
var wheeloffset = Random (0, 14);
var Location = Random (7);
var calc_year = 0;
var game_entry=false;

var newRowA = Scene.GetNode("RowA_Head");
var newRowAFilename = RowA[wheelpos];
var newRowB = Scene.GetNode("RowB_Head");
var newRowBFilename = RowB[wheeloffset];

var question = Scene.GetNode ("question");
var attempt1 = Scene.GetNode ("attempt1");
var attempt2 = Scene.GetNode ("attempt2");
var attempt3 = Scene.GetNode ("attempt3");

var Antigua = new Array ("1710","1651","1679","1719","1694","1632","1668","1703","1726","1564","1615","1599","1669","1660","1687");
var Barbados = new Array ("1725","1630","1709","1594","1614","1563","1649","1693","1577","1678","1686","1597","1718","1658","1702");
var Jamaica = new Array ("1613","1580","1723","1717","1684","1628","1643","1559","1573","1708","1701","1724","1667","1691","1685");
var Montserat = new Array ("1692","1656","1567","1674","1662","1655","1646","1671","1611","1672","1562","1721","1666","1673","1670");
var Nebraska = new Array ("1665","1706","1506","1722","1716","1584","1551","1627","1707","1688","1699","1568","1705","1579","1585");
var StKitts = new Array ("1712","1542","1565","1720","1664","1566","1592","1654","1635","1639","1695","1704","1711","1609","1681");
var Tortuga = new Array ("1604","1653","1641","1690","1682","1601","1619","1680","1021","1652","1689","1713","1697","1696","1624");

actor.Active = false;

// default values
if(StateRoom==null)
{
  StateRoom.Visited = false;
  // add scene states here
}

if(!StateRoom.Visited)
{
 entry_attempts = 1;
 while (entry_attempts<4)
   {
  calc_year = 0;
  wheelpos = Random (1,15); 
  wheeloffset = Random (0, 14);
  Location = Random (7);
  newRowAFilename = RowA[wheelpos];
          newRowBFilename = RowB[wheeloffset];
  newRowA.Active = false; 
  newRowA.SetSprite ("scenes\Room\" + newRowAFilename);
  newRowA.Active = true;
  newRowB.Active = false; 
  newRowB.SetSprite ("scenes\Room\" + newRowBFilename);
  newRowB.Active = true;
         
  var dialoffset = wheelpos-wheeloffset;
  if (dialoffset<1)
  {
    dialoffset = dialoffset + 15;
  }

  if (Location == 1) { question.SetSprite ("scenes\Room\loc_antigua.png");}
  if (Location == 2) { question.SetSprite ("scenes\Room\loc_barbados.png");} 
  if (Location == 3) { question.SetSprite ("scenes\Room\loc_jamaica.png");}
  if (Location == 4) { question.SetSprite ("scenes\Room\loc_montserat.png");}
  if (Location == 5) { question.SetSprite ("scenes\Room\loc_nebraska.png");}
  if (Location == 6) { question.SetSprite ("scenes\Room\loc_stkitts.png");}
  if (Location == 7) { question.SetSprite ("scenes\Room\loc_tortuga.png");}

  var WinMainMenu = Game.LoadWindow("interface\system\entry.window");
  //WinMainMenu.Center();
  WinMainMenu.GoSystemExclusive();
  Game.UnloadObject(WinMainMenu);
          if (Location == 1)
            {
    calc_year = Antigua[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }
          if (Location == 2)
            {
    calc_year = Barbados[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }
          if (Location == 3)
            {
    calc_year = Jamaica[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }
          if (Location == 4)
            {
    calc_year = Montserat[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }
          if (Location == 5)
            {
    calc_year = Nebraska[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }
          if (Location == 6)
            {
    calc_year = StKitts[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }
          if (Location == 7)
            {
    calc_year = Tortuga[dialoffset];
    if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}     
game_entry=true;
      }
      else
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }
    }

  entry_attempts=entry_attempts + 1; 
  if (game_entry==true) { break; }
  }         
       
  if (game_entry==false) { WinNarrator.DisplayText("Sorry. You need the Dial-A-Pirate to play this game.", 2000); Game.QuitGame();}
    else
    { WinNarrator.DisplayText("Congratulations! You are correct", 2000);}
 
  StateRoom.Visited = true;   
}
« Last Edit: April 01, 2005, 11:53:10 PM by revvin »
Logged

revvin

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 36
    • View Profile
Re: Can somebody help me improve my code?
« Reply #1 on: April 01, 2005, 11:53:27 PM »

Hi,
I have put together a script that I think needs tidying up. It works great - but I am know its too much code. I am pretty certain I need to utilise loops in a better way (would CASE loops help?) but I cant get my head around them. I just need some advice... can anybody help?
Many thanks,
Kev
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Can somebody help me improve my code?
« Reply #2 on: April 03, 2005, 08:34:32 PM »

That's some heavy code... What does it do? It looks like some copy protection scheme from the 90's :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Nihil

  • Supporter
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 528
  • Fear me! I'm evil!
    • View Profile
    • Order of Dagon
Re: Can somebody help me improve my code?
« Reply #3 on: April 04, 2005, 10:32:35 PM »

I just had a short look on the code and changed some things, but as it's already late and I couldn't test it I don't guarantee for anything :-)

Code: [Select]
#include "scripts\base.inc"
global WinNarrator;
global entry_attempts=0;

var RowA = new Array ("A1.png","A2.png","A3.png","A4.png","A5.png","A6.png","A7.png","A8.png","A9.png","A10.png","A11.png","A12.png","A13.png","A14.png","A15.png");
var RowB = new Array ("B1.png","B2.png","B3.png","B4.png","B5.png","B6.png","B7.png","B8.png","B9.png","B10.png","B11.png","B12.png","B13.png","B14.png","B15.png");
var Locations = new Array ("Antigua","Barbados","Jamaica","Montserat","Nebraska","St. Kitts","Tortuga");
var wheelpos = Random (1,15);
var wheeloffset = Random (0, 14);
var Location = Random (7);
var calc_year = 0;
var game_entry = false;

var newRowA = Scene.GetNode("RowA_Head");
var newRowAFilename = RowA[wheelpos];
var newRowB = Scene.GetNode("RowB_Head");
var newRowBFilename = RowB[wheeloffset];

var question = Scene.GetNode ("question");
var attempt1 = Scene.GetNode ("attempt1");
var attempt2 = Scene.GetNode ("attempt2");
var attempt3 = Scene.GetNode ("attempt3");

var Antigua = new Array ("1710","1651","1679","1719","1694","1632","1668","1703","1726","1564","1615","1599","1669","1660","1687");
var Barbados = new Array ("1725","1630","1709","1594","1614","1563","1649","1693","1577","1678","1686","1597","1718","1658","1702");
var Jamaica = new Array ("1613","1580","1723","1717","1684","1628","1643","1559","1573","1708","1701","1724","1667","1691","1685");
var Montserat = new Array ("1692","1656","1567","1674","1662","1655","1646","1671","1611","1672","1562","1721","1666","1673","1670");
var Nebraska = new Array ("1665","1706","1506","1722","1716","1584","1551","1627","1707","1688","1699","1568","1705","1579","1585");
var StKitts = new Array ("1712","1542","1565","1720","1664","1566","1592","1654","1635","1639","1695","1704","1711","1609","1681");
var Tortuga = new Array ("1604","1653","1641","1690","1682","1601","1619","1680","1021","1652","1689","1713","1697","1696","1624");

actor.Active = false;

// default values
if(StateRoom==null)
{
  StateRoom.Visited = false;
  // add scene states here
}

if(!StateRoom.Visited)
{
entry_attempts = 1;
while (entry_attempts<4)
{
  calc_year = 0;
  wheelpos = Random (1,15);
  wheeloffset = Random (0, 14);
  Location = Random (7);
  newRowAFilename = RowA[wheelpos];
  newRowBFilename = RowB[wheeloffset];
  newRowA.Active = false;
  newRowA.SetSprite ("scenes\Room\" + newRowAFilename);
  newRowA.Active = true;
  newRowB.Active = false;
  newRowB.SetSprite ("scenes\Room\" + newRowBFilename);
  newRowB.Active = true;
         
  var dialoffset = wheelpos-wheeloffset;
  if (dialoffset<1)
  {
    dialoffset = dialoffset + 15;
  }

var Dummie = ("scenes\Room\loc_" + Locations[Location] + ".png");
question.SetSprite (Dummie);


  var WinMainMenu = Game.LoadWindow("interface\system\entry.window");
  //WinMainMenu.Center();
  WinMainMenu.GoSystemExclusive();
  Game.UnloadObject(WinMainMenu);

  switch (Location)
  {
    case "1":
    calc_year = Antigua[dialoffset];
    break;

    case "2":
    calc_year = Barbados[dialoffset];
    break;
   
    case "3":
    calc_year = Jamaica[dialoffset];
    break;

    case "4":
    calc_year = Montserat[dialoffset];
    break;

    case "5":
    calc_year = Nebraska[dialoffset];
    break;

    case "6":
    calc_year = StKitts[dialoffset];
    break;
   
    case "7":
    calc_year = Tortuga[dialoffset];
    break;
  } //switch end

if (you_entered == calc_year)
      {
        if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box2.png");}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box2.png");}
game_entry=true;
      }
      else
      {
if (entry_attempts==1) {attempt1.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Whoops! You have two more chances.", 2000);}
        if (entry_attempts==2) {attempt2.SetSprite ("scenes\Room\box1.png"); WinNarrator.DisplayText("Hmm... wrong again.", 2000);}
        if (entry_attempts==3) {attempt3.SetSprite ("scenes\Room\box1.png");}
      }


  entry_attempts=entry_attempts + 1;
  if (game_entry==true) { break; }
} //while end
       
if (game_entry==false)
    { WinNarrator.DisplayText("Sorry. You need the Dial-A-Pirate to play this game.", 2000); Game.QuitGame();}
    else
    { WinNarrator.DisplayText("Congratulations! You are correct", 2000);}
 
  StateRoom.Visited = true;   
}

revvin

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 36
    • View Profile
Re: Can somebody help me improve my code?
« Reply #4 on: April 05, 2005, 08:54:53 PM »

Aha! superb! i'll give it a shot. Thanks Nihil.  :D

Yes, Mnemonic, its the copy-protection scheme from a famous nineties game that strangely had very little to do with monkeys...

Obviously let the cat out of the bag a little here - but one of the things I loved about the old school Graphic Adventures was the stuff that came in the boxes! Now you just get a dvd case with a disc. If you're lucky an instruction "card". Its almost clinical. :(

The copy protection wheels were part of the charm. I decided to use the original MI codewheel as a test to see if I could create the code behind a copy protection codewheel - and it worked!!! So I can now make my own wheel when I need to. :oD
Logged

candle

  • Amature Game Maker
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
  • Game Maker
    • View Profile
Re: Can somebody help me improve my code?
« Reply #5 on: April 11, 2005, 07:13:58 AM »

I have that wheel ..  ::rock

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re: Can somebody help me improve my code?
« Reply #6 on: April 15, 2005, 07:45:35 PM »

The copy protection wheels were part of the charm. I decided to use the original MI codewheel as a test to see if I could create the code behind a copy protection codewheel - and it worked!!! So I can now make my own wheel when I need to. :oD

Nice idea for sure. :)
Logged
Mooh!
 

Page created in 0.05 seconds with 20 queries.