Spherical forums

Sphere Development => Sphere Support => Script Support => Topic started by: Vakinox on July 05, 2013, 12:47:27 pm

Title: Menu Help
Post by: Vakinox on July 05, 2013, 12:47:27 pm
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:

(http://i.imgur.com/XNH5pyt.png)

This is what it should look like:

(http://i.imgur.com/uUPP13q.png)

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);
}

Title: Re: Menu Help
Post by: DaVince on July 05, 2013, 12:59:53 pm
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.
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 01:03:59 pm
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).
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 01:16:01 pm
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:

(http://i.imgur.com/RlO6Nff.png)

@Davince: How would I use RenderMap();?
I called it inside of the Interface() function and it told me impossible because "map isn't running."
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 01:46:01 pm
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
}
}
Title: Re: Menu Help
Post by: alpha123 on July 05, 2013, 01:56:28 pm
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;
                         }
                    }
            }
}
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 02:05:46 pm
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);
}
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 02:14:16 pm
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.
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 02:29:29 pm
@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...
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 03:30:15 pm
Yeah, no problem.

Attached.
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 03:35:25 pm
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)
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 04:40:35 pm
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.
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 05:29:42 pm
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
Title: Re: Menu Help
Post by: alpha123 on July 05, 2013, 06:02:18 pm

@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]
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 06:16:58 pm
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!

(http://i.imgur.com/vwMin.gif)

Actually, one last problem.
How do I make it go backwards once it reaches the fourth icon?
Presently it jumps back to the first.
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 06:31:33 pm


@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.


It's not a bad idea, not at all. I was just concerned of pacing that's all: newbies can lose interest if too much info is headed their way. Good call on the selection rolling, but now I must explain ternary operators.

@Vakinox:
To get it going left/right you'll have to handle it with different key presses, let's use A and D keys:
Code: (javascript) [Select]

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


Since again Alpha went full steam ahead, I'll explain what the ternary operator does.

The ternary operator is styled: ( cond ) ? if_true : if_false;
It will run the condition and then if that condition evaluates as true: for example, select < 4, then it runs the 'if_true' portion after the question mark (adds 1 to select), otherwise it does what's after the colon and sets select to 1 which is the 'if_false' part.
Title: Re: Menu Help
Post by: alpha123 on July 05, 2013, 06:40:56 pm

How do I make it go backwards once it reaches the fourth icon?
Presently it jumps back to the first.

That gets a little more complicated, but
Code: (javascript) [Select]
select = ((select >> 25) + 1 * ((select & 0x7F) - 1) << 25) | ((select >> 25) > 2 ? 0 : (select >> 25) < 3 ? 2 : (select & 0x7F))

should do the trick.
Alternatively, store a variable called select_direction or something and set that to 1 if select is 1, -1 if select is 4, or don't change it if select is 2 or 3. Then simply increment select by select_direction.
Radnen's right that you probably want two keys for this though. I think I use D and F for this in my game. Something like:
Code: (javascript) [Select]

var min = Math.min, max = Math.max;
while (AreKeysLeft()) {
    var key = GetKey();
    select = max(1, min(4, select + (key == KEY_D ? -1 : key == KEY_F ? 1 : 0)));
}

is how I'd do it, although Radnen's version is perfectly reasonable as well.


It's not a bad idea, not at all. I was just concerned of pacing that's all: newbies can lose interest if too much info is headed their way.

You mean, he might... learn something? Crazy, we can't have noobs learning.
And yes, it's a bad idea. The render script doesn't run at a fixed framerate, which will mess up input a lot. The engine attempts to run the update script at GetMapEngineFramerate() frames per second, which is much better for handling input.

Quote

Good call on the selection rolling, but now I must explain ternary operators.

I assumed he knows JavaScript syntax, but maybe not.

EDIT: Sorry for double posting.
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 06:51:29 pm
Don't be a smart ass, alpha. I don't want to warn you (I really can't anyways), because I know you do things like that on purpose.


Quote

Good call on the selection rolling, but now I must explain ternary operators.

I assumed he knows JavaScript syntax, but maybe not.


Even if he did, that may not mean he knows the ternary operator I know it took me a while before I found that out (by perusing tung's startup game).
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 06:55:42 pm
@Rad: as long as I been here, never encountered such a thing.
Thanks for the explanation too, really needed it. Understand now.
Both cool and useful, any tutorials involving operators such as these?

@alpha: that is definitely more complicated.

Attempted to do the variable one instead:
Code: (javascript) [Select]

var select_direct = 1;

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


However it doesn't work. Any ideas?
The icons just disappear.
Title: Re: Menu Help
Post by: alpha123 on July 05, 2013, 06:57:20 pm

Don't be a smart ass, alpha. I don't want to warn you (I really can't anyways), because I know you do things like that on purpose.

Are you referring to the (working, BTW) snippet with the bitwise operators above? Sorry, perhaps that was a little over-the-top. I apologize. I just tend to get a little irritated when I can tell someone didn't even really try to figure a problem out.

Quote

Even if he did, that may not mean he knows the ternary operator I know it took me a while before I found that out (by perusing tung's startup game).

It's not like it's particularly obscure or anything (to the contrary, it's used quite often), but I suppose it may be a tad cryptic to someone not used to JavaScript.


@alpha: that is definitely more complicated.

That was me being a jerk, don't use it.

Quote

Attempted to do the variable one instead:
Code: (javascript) [Select]

var select_direct = 1;

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


However it doesn't work. Any ideas?
The icons just disappear.

Declare select_direction at the top level with select, so it looks like
Code: (javascript) [Select]
var select = 1, select_direction = 1;
function Interface_Render()
{
     ...
}
function Interface_Update()
{
    ...
}


Then use
Code: (javascript) [Select]

select += select_direction;
if (select == 1)
    select_direction = 1;
else if (select == 4)
    select_direction = -1;

in enter-handling code in Interface_Update.
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 07:00:57 pm
@Vakinox: I agree with you, alpha did give you unpractical example.

@alpha: Sorry if I'm combating your opinion, you just don't seem to have the teaching vibe when you post. But you are right Vakinox should try a little harder, but it's hard when you are first starting out.

Here is a full, prototyped example of what you can do with a (1, -1) ranged vector for the select. I'm sure this is the easiest to comprehend version. If you notice, when select_direct is equal to 1 it adds, and -1 it subtracts. And the states 1 and 4 toggle the behavior. :)

Code: (javascript) [Select]

var select_direct = 1; // make sure that is global
var select = 1;

function game() {
SetRenderScript("GetSystemFont().drawText(0, 0, select);")
SetUpdateScript("Update();");
MapEngine("testmap.rmp", 60);
}

function Update() {
while (AreKeysLeft()) {
if (GetKey() == KEY_ENTER) {
select += select_direct;

if (select == 1) select_direct *= -1;
if (select == 4) select_direct *= -1;
}
}
}
Title: Re: Menu Help
Post by: Flying Jester on July 05, 2013, 07:08:36 pm



@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.



As far as I know, this is important primarily for the opposite: don't draw in the update script.
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 07:10:58 pm
@Rad: Thanks mate.

@Alpha: Look, I understand the demeanor.
Apologies if it seems I'm not trying, but for explanation purposes
I have a problem with memory possibly due to mental issues, which I'm still trying to find medication for, and thus am having to relearn scripting again.
Among other things.

I've done this several times now (3rd in counting), and am at it again. It's a piss poor excuse, but
if I wasn't actually trying, I wouldn't be posting new iterations of the code.
What you're seeing is a limitation of ability, not effort.

To me, it's hard to pick up new things such as languages.
And I have to have enough patience to re-digest some of the problems I may have had before, embarrassing as it may be.
All I ask is to bare a small amount of time to help me relearn this stuff.

For me, most operators are fairly obscure.
Most projects made by expert users here, seem to read like noise without proper documentation explaining it.
This is probably the first time I've come across the operator you've used, and actually understood it.
Truthfully. Just please understand man.
And thank you for taking the time to do this.
Title: Re: Menu Help
Post by: Radnen on July 05, 2013, 07:14:13 pm
@vakinox: I'm sorry to hear that, I too have a disability but it's not mental it's physical. My left arm shakes a bit due to a stroke I had when I was 7 so I usually type with 1 hand.

Since I edited when you posted, did you check out the new tutorial I wrote? You might find the use of select_direct interesting in that example.
Title: Re: Menu Help
Post by: alpha123 on July 05, 2013, 07:20:41 pm

@alpha: Sorry if I'm combating your opinion, you just don't seem to have the teaching vibe when you post. But you are right Vakinox should try a little harder, but it's hard when you are first starting out.

I know. You're a far, far better teacher than I am. Perhaps that's because I learned to code working by myself from library books. I didn't get on any internet coding sites for years after I started.
Still, it's not all that difficult to ask yourself, "How can I solve this problem?" before you post asking how to solve that problem.

Quote

Code: (javascript) [Select]
if (select == 1) select_direct *= -1;
if (select == 4) select_direct *= -1;


That could be replaced with
Code: (javascript) [Select]
select_direct *= (select == 1 || select == 4) * -2 + 1

but perhaps that's getting a little too compact.


I'm sorry Vakinox. You're quite a talented artist, regardless. :)


As far as I know, this is important primarily for the opposite: don't draw in the update script.

Yes, that's more important. However, doesn't the game loop go:
Code: [Select]
while (true) {
    // UpdateMapEngine() is equivalent to the next two calls.
    UpdateEngine();
    CallUpdateScripts();
    // RenderMap() is equivalent to the next two calls.
    RenderImage();
    CallRenderScripts();
}

which means if you handle input in the render script after you draw, it won't be picked up until the next render.
Title: Re: Menu Help
Post by: Flying Jester on July 05, 2013, 07:32:51 pm


As far as I know, this is important primarily for the opposite: don't draw in the update script.

Yes, that's more important. However, doesn't the game loop go:
Code: [Select]
while (true) {
    // UpdateMapEngine() is equivalent to the next two calls.
    UpdateEngine();
    CallUpdateScripts();
    // RenderMap() is equivalent to the next two calls.
    RenderImage();
    CallRenderScripts();
}

which means if you handle input in the render script after you draw, it won't be picked up until the next render.


You know, all I remember is that it won't work like you want it to if you assume there's no real difference between the two. To be fair, one frame of delay shouldn't really be noticeable even at 30 FPS, though.
Title: Re: Menu Help
Post by: Vakinox on July 05, 2013, 07:42:29 pm
Quote
Still, it's not all that difficult to ask yourself, "How can I solve this problem?" before you post asking how to solve that problem.


Hardly that easy when there isn't sufficient knowledge of the tools (code) to help one solve the problem.
It also takes a good deal of skill and experience with mathematical problem solving, of which I'm pretty inexperienced with.
And spending a good couple of years outta high school, without furthering your education, doesn't help familiarize yourself with it either.

One thing I can point out now, is that I don't understand what the asterisk is doing within the code other than multiplying.
And what it's multiplying an equal sign for I couldn't guess or figure out anyways.
Currently searching a Mozilla site for an explanation.

Quote
I'm sorry Vakinox. You're quite a talented artist, regardless.


Please don't patronize.

You're definitely by far an excellent coder. And your code works beautifully.
Just try to take it slow when working with us newbs.
Title: Re: Menu Help
Post by: alpha123 on July 05, 2013, 08:21:19 pm

One thing I can point out now, is that I don't understand what the asterisk is doing within the code other than multiplying.
And what it's multiplying an equal sign for I couldn't guess or figure out anyways.
Currently searching a Mozilla site for an explanation.

select_direct *= x is equivalent to select_direct = select_direct * x.
This (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) is a good operator reference, especially in conjunction with their precedences (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence), if you haven't found those yet. MDN is a good site.

Quote

Please don't patronize.

You're definitely by far an excellent coder. And your code works beautifully.
Just try to take it slow when working with us newbs.

That wasn't meant to be patronizing; sorry if it came off that way. I apologized for being quite rude to you, and even if you're not a particularly good coder (yet) I legitimately quite like the style of your art.
Title: Re: Menu Help
Post by: N E O on July 06, 2013, 01:48:27 pm
What was the original purpose of this thread, something about menus? It seems to have been guided a bit off-topic.