Skip to main content

News

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

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #15


@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.
  • Last Edit: July 05, 2013, 06:35:46 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 #16

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.
  • Last Edit: July 05, 2013, 06:53:29 pm by alpha123

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #17
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).
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 #18
@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.

Re: Menu Help
Reply #19

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.
  • Last Edit: July 05, 2013, 07:07:49 pm by alpha123

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #20
@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;
}
}
}
  • Last Edit: July 05, 2013, 07:11:14 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 #21



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

Re: Menu Help
Reply #22
@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.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Menu Help
Reply #23
@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.
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 #24

@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.
  • Last Edit: July 05, 2013, 07:24:37 pm by alpha123

Re: Menu Help
Reply #25


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.

Re: Menu Help
Reply #26
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.

Re: Menu Help
Reply #27

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 is a good operator reference, especially in conjunction with their precedences, 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.

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: Menu Help
Reply #28
What was the original purpose of this thread, something about menus? It seems to have been guided a bit off-topic.