I bet you can't explain this (proof programming languages are illogical).

EricL1

Member
--SOLVED, SOLUTION IN MY FINAL POST--

Hey everyone, I think I've finally found something more illogical than the 20 character password I needed to register for this forum.

Anyway I was making great progress in my game, liking the fact that programming languages were logical until... they were not.

So here's a very simple riddle for you. No labyrinthine code segments here.

if(keyboard_check_pressed(ord("1")))
{
UsedItem=global.Inventory1
global.Inventory1=""
}


It does not work. The UsedItem is receiving nothing, though the global.Inventory1 is.

But here's what does work. Note the miniscule and completely inconsequential changes.

if(keyboard_check_pressed(ord("0")))
{
UsedItem=global.Inventory1
global.Inventory1=""

}

if(keyboard_check_pressed(ord("1")))
{
UsedItem=global.Inventory2
global.Inventory2=""

}

So I'm trying to wrap my head around this. Apparently there is some bizarre and almost ludicrous interaction between the use of 'ord 1' and 'global inventory 1'. What could it be? Are programming languages really logical?

I've monitored and debugged this from every angle. All variables are being drawn on my screen. I've isolated every single statement in here. There is no conceivable reason this should not work. Of course as a workaround I could just change it to 'ord 0' and be done with it, however this is part of a user input from a sequence of numbers, and going from '0' to '2' would be a little odd.
 
Last edited:

Nidoking

Member
I bet you didn't post the part where the problem actually is. There's some interaction between either inputs or variables that you're not accounting for. Doubting the logic of programming languages is a pretty sure sign that you probably just don't understand what you're doing well enough to identify the actual problem. But do feel free to post the rest of the information so someone can actually help you.
 

TailBit

Member
The problem could be that the code try to set UsedItem two places on the press of 1 .. but that is just a guess with the information given
 

EricL1

Member
I bet you didn't post the part where the problem actually is. There's some interaction between either inputs or variables that you're not accounting for. Doubting the logic of programming languages is a pretty sure sign that you probably just don't understand what you're doing well enough to identify the actual problem. But do feel free to post the rest of the information so someone can actually help you.
Certainly possible. Also possible you didn't read my post fully. :)

Anyway I think it's wonderful that people wish to help others on this message board, so I'll try to simplify it even further as not to waste anyone's time.

Take this code:

if(keyboard_check_pressed(ord("1")))
{
UsedItem=global.Inventory1
}

Why would this not work? but this would:

if(keyboard_check_pressed(ord("0")))
{
UsedItem=global.Inventory1
}

if(keyboard_check_pressed(ord("1")))
{
UsedItem=global.Inventory2
}

Maybe it would be easier for someone to 'reverse engineer' a problem than me to post hundreds of lines of long code. Maybe I don't know what I'm doing (I surely think I do), but after hours analyzing these two lines of code and anything relating to them and being confronted by the absurd dichotomies above, I thought it not injudicious not only to register here but to make my first post.
 

Roldy

Member
First use the code tool when submitting code on this forum:

1626813428525.png


I've monitored and debugged this from every angle
What is the value of 'UsedItem' and ' global.Inventory1 ' when you step through that conditional block in the debugger?

Ctrl+shift+F find all instances of 'UsedItem' in your code and place a breakpoint at each. Which location is getting hit that causes your undesired behavior? Which locations are not getting hit that you expected them too?

Debugger

It does not work. The UsedItem is receiving nothing, though the global.Inventory1 is.
Again, What is the value of 'UsedItem' and ' global.Inventory1 ' when you step through that conditional block in the debugger?
 

TailBit

Member
You changed the "1" to "0" .. but you show here that the other line also try to check for "1" .. making global.Inventory2 clear UsedItem
Code:
if(keyboard_check_pressed(ord("0")))
{
    UsedItem=global.Inventory1
    global.Inventory1=""
}

if(keyboard_check_pressed(ord("1")))
{
    UsedItem=global.Inventory2
    global.Inventory2=""
}
 

EricL1

Member
I was just showing that as an example of how it could be changed Tailbait. Anyway thanks everyone for your comments because--they've helped me deduce the solution! It turns out I was the illogical one after all. LOL! A further sample of my code would have shown why. I had assigned 'ords' '10', '11', '12', etc. to global.Inventory10, 11, 12, etc. How was the user going to press '11' on his keyboard?šŸ˜ Apparently this interferes in some strange way with the code. Probably trying to read an 'ord 11' it reads the one first and that interferes with the 'ord 1'. Of course consulation of the manual also reveals that there is no 'ord 10'.

Whew! Thank heavens for these forums. :)
 

kburkhart84

Firehammer Games
I'm glad you figured it out. Future reference, you might want to get a list of keycodes and use those instead. Most keys use constants like vk_xxx, which are those keycodes. But the letters and numbers also have keycodes which you can use, saving the need to ever need the ord() function.
 

Nidoking

Member
I'm glad you figured it out. Future reference, you might want to get a list of keycodes and use those instead. Most keys use constants like vk_xxx, which are those keycodes. But the letters and numbers also have keycodes which you can use, saving the need to ever need the ord() function.
And also confusing you in the future when you can't remember which keycode does what and have to keep going back to the table. ord("1") is a lot easier to recognize at a glance.

Probably trying to read an 'ord 11' it reads the one first and that interferes with the 'ord 1'.
ord("11"), in the contexts where that doesn't cause an error, is exactly equal to ord("1"), or ord("123456"), or ord("1partridgeinapeartree"). It can only give a keycode for one character, because keycodes are for single characters. This is why I said
There's some interaction between either inputs or variables that you're not accounting for.
And also, as I said, the part where the problem was wasn't in your post, no matter how fully I read it. Good thing you figured it out, at least.
 

Roldy

Member
@EricL1 Your biggest mistake was assuming the problem was elusive, not internal to yourself. If you are going to assume anything then always assume the error is your own. This will speed up your process of finding solutions. Errors and mistakes are part of the process and you will continuously cause these problems for yourself, every one does, I do, the skill is in finding the error accurately and making solutions quickly.

The debugger, your growing experience and forums like this are your best tools.

Welcome and good luck.
 
I know that the topic has already been solved, but I will just say. There is a very slim chance the problem is actually a bug in gm. But you could probably find out in a quick Google search
 

EvanSki

Raccoon Jam Host
I was just showing that as an example of how it could be changed Tailbait. Anyway thanks everyone for your comments because--they've helped me deduce the solution! It turns out I was the illogical one after all. LOL! A further sample of my code would have shown why. I had assigned 'ords' '10', '11', '12', etc. to global.Inventory10, 11, 12, etc. How was the user going to press '11' on his keyboard?šŸ˜ Apparently this interferes in some strange way with the code. Probably trying to read an 'ord 11' it reads the one first and that interferes with the 'ord 1'. Of course consulation of the manual also reveals that there is no 'ord 10'.

Whew! Thank heavens for these forums. :)
I'm glad you figured it out. Future reference, you might want to get a list of keycodes and use those instead. Most keys use constants like vk_xxx, which are those keycodes. But the letters and numbers also have keycodes which you can use, saving the need to ever need the ord() function.

or take 2 secs to look up utf-8 codes
if youre using the top row number keys
why go through pain and use unicode?
use the virtal keys
if youre using wasd then use ord("W")


And also confusing you in the future when you can't remember which keycode does what and have to keep going back to the table. ord("1") is a lot easier to recognize at a glance.



ord("11"), in the contexts where that doesn't cause an error, is exactly equal to ord("1"), or ord("123456"), or ord("1partridgeinapeartree"). It can only give a keycode for one character, because keycodes are for single characters.
^^^^
 

kburkhart84

Firehammer Games
And also confusing you in the future when you can't remember which keycode does what and have to keep going back to the table. ord("1") is a lot easier to recognize at a glance.
Or make #macros, possibly even following the whole vk_xxxx scheme.. Then you get autocomplete, save the function call, AND get easy readability. To each his own I guess, but I find that ord("") function much less clear than vk_xxx.
 
Top