Skip to main content

News

Topic: Menu Help (Read 5884 times) previous topic - next topic

Menu Help
Noobish problem, but I be a little rusty with my scripting.
The Code:

Code: [Select]
 

function Interface()
{
var done = false;
var select = 1;

while(AreKeysLeft()) {GetKey();}
while(done == false) {

  win2.drawWindow(x+1,y+h-15,w-2,14);
  icon01.blit(x+45, y+h-16)
  icon02.blit(x+62, y+h-16)
  icon03.blit(x+79, y+h-16)
  icon04.blit(x+96, y+h-16)
 
  FlipScreen();
 
   while(AreKeysLeft()) {
    switch(GetKey()) {
   
     case KEY_ENTER:
     select++;
     if (select = 1) {
      Picon01.blit(x+45, y+h-16);
      icon02.blit(x+62, y+h-16)
      icon03.blit(x+79, y+h-16)
      icon04.blit(x+96, y+h-16)
     }
     if (select = 2) {Picon02.blit(x+62, y+h-16);}
     if (select = 3) {Picon03.blit(x+79, y+h-16);}
     if (select = 4) {Picon04.blit(x+96, y+h-16);}
     if (select >= 4) {select--;}
     if (select <= 1) {select++;}
     break;
     }
    }
  }
}



I've tried running it by itself, and through a SetRenderScript(); to no avail.
This is what it looks like:



This is what it should look like:



What should happen within the interface, is the icons should change (depending on which is selected)
from icon01 to Picon01 ("P" = "pressed") every time "ENTER" is keyed in. 
Any suggestions?

. . . .

And while we're at it.
Shouldn't this work too, when put through a SetRenderScript();?:

Code: [Select]

var Debug = false;

function Render()
{
if (IsKeyPressed(KEY_CTRL)){
if (Debug == true) {Debug = false;}
else if (Debug == true) {DrawDebug();}
}

}


function DrawDebug()
{
  //wind.drawWindow(x+4,y+h-35,w-8,31);
  wind.drawWindow(x+3,y+h-18,w-6,15);
  font.drawText(x+4,y+h-17, "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]");
  font.drawText(x+4,y+h-10, "0123456789 ABDP,C.E");
  //font.drawText(x+65,y+h-9, "N_X: " + NowTileX);
}

  • Last Edit: July 05, 2013, 12:58:10 pm by Vakinox

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Menu Help
Reply #1
Don't FlipScreen() in a renderscript; the engine does it for you. If you do, it basically gets rid of whatever the map engine itself was rendering.

Edit: wait, just noticed your first code block wasn't using SetRenderScript(). In that case, you forgot RenderMap() in order to display the map as a background.
  • Last Edit: July 05, 2013, 01:03:25 pm by DaVince

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #2
So for the first bit of stuff you must do 2 things.

1. Remove the FlipScreen from Interface. It's not needed since the REnderScript will do that for you.
2. Remove the while loop. Because the RenderScript already runs in a while loop - the map engine's.

By doing the above 2 things the Interface will run on top of the map engine, without pausing it.

Foe debug, you need to do one change and move the Debug == true section out of the ctrl key handler:
Code: (javascript) [Select]

function Render()
{
if (Debug) { DrawDebug(); } // notice you don't need Debug == true
if (IsKeyPressed(KEY_CTRL)) {
if (Debug) { Debug = false; }
}

}


Also I don't know if you know this, but you can only set one script at a time for RenderScript:
Code: (javascript) [Select]

function game()
{
    SetRenderScript("Render();");
    SetRenderScript("Interface();"); // Render() has been removed.
}


So you'll have to add a call to Interface() inside of Render for it to work. Or Use Interface and put a call to Render() inside of it (whichever you used for the RenderScript).
  • Last Edit: July 05, 2013, 01:06:41 pm by Radnen
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Menu Help
Reply #3
Removed the Debug == true, but still isn't working:

Code: [Select]
 
function Render()
{
  if (Debug) { DrawDebug(); }
  if (IsKeyPressed(KEY_CTRL)) {
   if (Debug) { Debug = false; }
  }     
}


Don't you need something in the script though to
transition "Debug = false" back to "Debug = true" when KEY_CTRL is pressed?
Just tried anyways, doesn't work.

And removed the while-loops out of the Interface function:

Code: [Select]
 
function Interface()
{
var done = false;
var select = 1;

  win2.drawWindow(x+1,y+h-15,w-2,14);
  switch(GetKey()) {
 
   case KEY_ENTER:
     select++;
     if (select = 1) {
      Picon01.blit(x+45, y+h-16)
      icon02.blit(x+62, y+h-16)
      icon03.blit(x+79, y+h-16)
      icon04.blit(x+96, y+h-16)}
     if (select = 2) {Picon02.blit(x+62, y+h-16);}
     if (select = 3) {Picon03.blit(x+79, y+h-16);}
     if (select = 4) {Picon04.blit(x+96, y+h-16);}
     if (select >= 4) {select--;}
     if (select <= 1) {select++;}
     break;
     }
}


However, it still isn't working either.
Instead getting a black screen,
then when ENTER is pressed I get this:



@Davince: How would I use RenderMap();?
I called it inside of the Interface() function and it told me impossible because "map isn't running."
  • Last Edit: July 05, 2013, 01:29:23 pm by Vakinox

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #4
Ok, you can'u use local function storage quite easily in a render or update script. So you'll need to create some global variables.

Code: (javascript) [Select]

var select = 1;
function Interface()
{
win2.drawWindow(x+1,y+h-15,w-2,14);

if (select == 1) { // '==' is a comparison.
Picon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 2) {
icon01.blit(x+45, y+h-16);
Picon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 3) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
Picon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 4) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
Picon04.blit(x+96, y+h-16);
}

while (AreKeysLeft()) {
switch(GetKey()) {
case KEY_ENTER:
if (select >= 4) { select--; }
if (select <= 1) { select++; }
break;
     }
}
}
}


As for Debug, to handle a toggle:
Code: (javascript) [Select]

var show_debug = false;

function Render()
{
if (show_debug) { DrawDebug(); }
while (AreKeysLeft()) {
if (GetKey() == KEY_CTRL) show_debug = !show_debug; // toggles debug
}
}
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Menu Help
Reply #5
Don't do input handling in a render script! That should be in an update script.

Code: (javascript) [Select]

    var select = 1;
function Interface_Render()
{
            win2.drawWindow(x+1,y+h-15,w-2,14);
    
            if (select == 1) { // '==' is a comparison.
                    Picon01.blit(x+45, y+h-16);
                    icon02.blit(x+62, y+h-16);
                    icon03.blit(x+79, y+h-16);
                    icon04.blit(x+96, y+h-16);
            }
            if (select == 2) {
                    icon01.blit(x+45, y+h-16);
                    Picon02.blit(x+62, y+h-16);
                    icon03.blit(x+79, y+h-16);
                    icon04.blit(x+96, y+h-16);
            }
            if (select == 3) {
                    icon01.blit(x+45, y+h-16);
                    icon02.blit(x+62, y+h-16);
                    Picon03.blit(x+79, y+h-16);
                    icon04.blit(x+96, y+h-16);
            }
            if (select == 4) {
                    icon01.blit(x+45, y+h-16);
                    icon02.blit(x+62, y+h-16);
                    icon03.blit(x+79, y+h-16);
                    Picon04.blit(x+96, y+h-16);
            }
}
function Interface_Update()
{
            while (AreKeysLeft()) {
                    switch(GetKey()) {
                            case KEY_ENTER:
                                    if (select >= 4) { select--; }
                                    if (select <= 1) { select++; }
                            break;
                         }
                    }
            }
}

Re: Menu Help
Reply #6
Alright, the Interface function is being drawn on screen.
Problem though is the buttons aren't switching,
meaning, I'm guessing, the variable "select" isn't being affected.

So I tried this:

Code: [Select]

SetRenderScript("Interface(1)");

var select = 1;
function Interface(select)
{
win2.drawWindow(x+1,y+h-15,w-2,14);

if (select == 1) {
Picon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 2) {
icon01.blit(x+45, y+h-16);
Picon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 3) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
Picon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 4) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
Picon04.blit(x+96, y+h-16);
}

while (AreKeysLeft())
{ switch(GetKey()) {
case KEY_ENTER:
if (select >= 4) { select--; }
if (select <= 1) { select++; }
break;
}
}
}


Running the variable through the parentheses, and changing the variable called in the parentheses works,
but still isn't affected when the ENTER key is pressed. Any ideas?

And two other questions to help understand:
Why does "select" have to be a Global variable, instead of Local?
And I also though you said SetRenderScript() already runs in a while-loop, and that we shouldn't use them? Special case?

. . .

Also, Debug still isn't working.
And the variable "Debug" was a toggle,
atleast that's what I thought I was scripting it as with the whole false v.s. true bit.

Code: [Select]
 
//----------DeBug------------\\

var Debug = false;
var show_debug = false;

function Render()
{
  if (show_debug) { DrawDebug(); }
  while (AreKeysLeft()) {
   if (GetKey() == KEY_CTRL) show_debug = !show_debug;
  }
}

function DrawDebug()
{
  //wind.drawWindow(x+4,y+h-35,w-8,31);
  wind.drawWindow(x+3,y+h-18,w-6,15);
  font.drawText(x+4,y+h-17, "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]");
  font.drawText(x+4,y+h-10, "0123456789 ABDP,C.E");
  //font.drawText(x+65,y+h-9, "N_X: " + NowTileX);
}

Re: Menu Help
Reply #7
Caught the new message, here's the result:

Code: [Select]
 
SetUpdateScript('Movement()');
SetRenderScript("Interface_Render()");
SetUpdateScript("Interface_Update()");

var select = 1;
function Interface_Render()
{
win2.drawWindow(x+1,y+h-15,w-2,14);

if (select == 1) { // '==' is a comparison.
Picon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 2) {
icon01.blit(x+45, y+h-16);
Picon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 3) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
Picon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 4) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
Picon04.blit(x+96, y+h-16);
}
}

function Interface_Update()
{
while (AreKeysLeft()) {
switch(GetKey()) {
case KEY_ENTER:
if (select >= 4) { select--; }
if (select <= 1) { select++; }
break;
}
}
}


Now there's already an UpdateScript() in place for tile movement.
Does that conflict with the other UpdateScript() we're creating for the interface?
Because now, Movement() doesn't work... meaning no controls at all.

And the interface does work, except it only moves one time.
Meaning, I can press ENTER once and it moves, then stops working.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #8
@Alpha123: nothing stops anyone from doing input in a renderscript, it's how I first learned before I started splitting things up, we've gpt to build up to that. ;)

@Vakinox:
Since alpha gave you a plunge into update script, you have to know that it works similarly as render script in that setting one will replace the other. So, you need to create a general function and put all of your updates into that function:
Code: (javascript) [Select]

function game()
{
    SetUpdateScript("MyUpdate();");
}

function MyUpdate() {
    Movement();
    Interface_Update();
}


Can you post the full code file? I wonder if you put select into the global scope or not...
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Menu Help
Reply #9
Yeah, no problem.

Attached.

Re: Menu Help
Reply #10
Alright, put everything under one UpdateScript()
Here:

Code: (javascript) [Select]
 
SetUpdateScript('Update()');

function Update()
{
Movement();
Interface_Update();
}


It works, HALLELUIAH!
However one problem persists.
The interface only works one time.
Press ENTER once, stops working.
Suggestions?

Code: (javascript) [Select]
 
var select = 1;
function Interface_Render()
{
win2.drawWindow(x+1,y+h-15,w-2,14);

if (select == 1) { // '==' is a comparison.
Picon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 2) {
icon01.blit(x+45, y+h-16);
Picon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 3) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
Picon03.blit(x+79, y+h-16);
icon04.blit(x+96, y+h-16);
}
if (select == 4) {
icon01.blit(x+45, y+h-16);
icon02.blit(x+62, y+h-16);
icon03.blit(x+79, y+h-16);
Picon04.blit(x+96, y+h-16);
}
}

function Interface_Update()
{
while (AreKeysLeft()) {
switch(GetKey()) {
case KEY_ENTER:
if (select >= 4) { select--; }
if (select <= 1) { select++; }
break;
}
}
}


(edit - fixed code tags to fix non-displaying text and to highlight as js ~neo)
  • Last Edit: July 05, 2013, 03:48:06 pm by N E O

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #11
Aha, the conditionals need reversing,

Code: (javascript) [Select]

                if (select >= 1) { select--; }
                if (select <= 4) { select++; }


When you decrease you want to go no lower than 1, and when you increase you want to go no higher than 4.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Menu Help
Reply #12
Now it isn't working at all :/
(press ENTER, does nothing)

. . .

[Edit:] Made some progress:

Code: [Select]
 
if (select > 1 && select < 4) { select++; }
if (select == 1) { select++; }
if (select == 4) { select--; }


it now moves one space more than it normally does, THEN quits.

[Sidenote:] What are the proper tags for the Javascript?
Used [js] [/js] and every other variant but nothing happens
  • Last Edit: July 05, 2013, 06:04:38 pm by Vakinox

Re: Menu Help
Reply #13

@Alpha123: nothing stops anyone from doing input in a renderscript, it's how I first learned before I started splitting things up, we've gpt to build up to that. ;)

That doesn't stop it from being a terrible idea.


When you decrease you want to go no lower than 1, and when you increase you want to go no higher than 4.

Code: (javascript) [Select]
select = Math.max(0, Math.min(4, select + 1));

is the idiomatic way to do that.
However, since he almost certainly wants it to wrap around, that would be
Code: (javascript) [Select]
select = select < 4 ? select + 1 : 1;



[Sidenote:] What are the proper tags for the Javascript?
Used [js] [/js] and every other variant but nothing happens

[code=javascript][/code]
  • Last Edit: July 05, 2013, 06:07:08 pm by alpha123

Re: Menu Help
Reply #14
Quote
However, since he almost certainly wants it to wrap around, that would be:
Code: (javascript) [Select]
 
select = select < 4 ? select + 1 : 1;



YES. you win da internetz!



Actually, one last problem.
How do I make it go backwards once it reaches the fourth icon?
Presently it jumps back to the first.