Author Topic: Need help (please) with magic token data comparison  (Read 3018 times)

Retrozz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Need help (please) with magic token data comparison
« on: August 16, 2020, 02:22:41 PM »
Hi,

I am working on the latest MyRetrozz Mini (blatant plug) and stumbled across what I would have thought would be the easiest thing to do.. yet after 2 hours of trying many (some silly) options I am stuck and I need help...

Here is the data I am using as source (just a sample for testing):

#Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra
.\VIC20\Games\[CRT]\Multipart\Adventureland (1981)(Commodore)[SYS 32592].zip;Adventureland (1981)(Commodore)[SYS 32592];vic_games;Adventureland (1981)(Commodore)[SYS 32592];;;16k;;;;;;NTSC;;;games

The field I am using is 'Category'

Side note.. if this helps anyone for something else.. this part works fine:

local memtype = fe.add_image ( "[Category].png", flx*0.364583333333, fly*0.4351851851851852, flw*0.1171875, flh*0.1134259259259259);

Here is where it does NOT work..

I need to set up specific conditions based on which 'Category' I am using, i.e. the value, 3k, 8k, 16k, 24k and this is (presumably) just text because it works in showing the correct picture on the screen.

What I thought was reasonable was (this is a debugging test):

if ("[Category]" == "16k" )
{
   local debug_showtext = fe.add_text( "16k cart found!", 1900, 260, 500, 150);
   debug_showtext.char_size = 20;
}

yet the condition never hits true.. if I do >= it will always show but that just shows the if and operand are at least doing something

I tried this variant (before I tried really silly options which are to ludicrous to show here):

local testvariable = "[Category]";
local debug_showtext = fe.add_text( testvariable, 1900, 240, 500, 150); <--- this does show something on the screen properly so I know the variable has the correct data
debug_showtext.char_size = 20;

if (testvariable == "16k" )
{
   local debug_showtext = fe.add_text( "16k cart found!", 1900, 260, 500, 150);
   debug_showtext.char_size = 20;
}


Help!

Thank You,

Retrozz  8)









keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Need help (please) with magic token data comparison
« Reply #1 on: August 16, 2020, 02:54:35 PM »
You are using a magic token outside of the scope of where it should be applied. Read layouts.md carefully. Your if statement is comparing two strings. Use fe.game_info().

https://github.com/mickelson/attract/blob/master/Layouts.md#magic
https://github.com/mickelson/attract/blob/master/Layouts.md#game_info

Retrozz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Need help (please) with magic token data comparison
« Reply #2 on: August 16, 2020, 07:34:36 PM »
Thanks! I'll try that tomorrow when I have time and post results.

Retrozz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Need help (please) with magic token data comparison
« Reply #3 on: August 24, 2020, 10:36:55 PM »
Sorry for delay.. got distracted (Flight Sim 2020 launch :) )

I am still  having a really hard time getting this to work properly.. here is my latest iteration:

// Check memory requirements for VIC20
//
function get_memory()
{
   local vic_mem = fe.game_info( Info.DisplayCount, 0 , 0 );
   return vic_mem;
}

if ([!get_memory] == "blah" )
{
   fe.add_text( "[!get_memory]", 1900, 260, 500, 150);
}

No matter what I test for with the IF command I can never get a match.. I've tried 1, "1" for a numeric value, tried a string value.. to no avail.

If I do a != it will just show every value.. it's essentially not working the same way it didn't when I was (improperly) using the magic token outside a fe.game_info() function <- as as said, I've tried different tokens in case some had to be numeric, or text, etc.

I can put whatever 'values' I need in the magic tokens (the game list) but I just need to be able to check the value consistently.

Please help!

Thank You.


Note: I've tried various 'magic tokens' and have a list with the following:

.\VIC20\Games\[CRT]\Multipart\Adventureland (1981)(Commodore)[SYS 32592].zip;Adventureland (1981)(Commodore)[SYS 32592];vic_games;Adventureland (1981)(Commodore)[SYS 32592];;;;;;;;1;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\AE (1982)(Broderbund).zip;AE (1982)(Broderbund);vic_games;AE (1982)(Broderbund);;;;;;;;2;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\AE (1982)(Broderbund)[a2].zip;AE (1982)(Broderbund)[a2];vic_games;AE (1982)(Broderbund)[a2];;;;;;;;3;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\AE (1982)(Broderbund)[a].zip;AE (1982)(Broderbund)[a];vic_games;AE (1982)(Broderbund)[a];;;;;;;;4;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\Alphabet Zoo (1982)(HES)(NTSC).zip;Alphabet Zoo (1982)(HES)(NTSC);vic_games;Alphabet Zoo (1982)(HES)(NTSC);;;;;;;;5;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\Alphabet Zoo (1982)(HES)(NTSC)[h][6000].zip;Alphabet Zoo (1982)(HES)(NTSC)[h][6000];vic_games;Alphabet Zoo (1982)(HES)(NTSC)[h][6000];;;;;;;;6;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\Apple Panic (1982)(Creative).zip;Apple Panic (1982)(Creative);vic_games;Apple Panic (1982)(Creative);;;;;;;;7;NTSC;;;games
.\VIC20\Games\[CRT]\Multipart\Apple Panic (1982)(Creative)
  • .zip;Apple Panic (1982)(Creative)
  • ;vic_games;Apple Panic (1982)(Creative)
  • ;;;;;;;;8;NTSC;;;games

.\VIC20\Games\[CRT]\Multipart\Apple Panic (1982)(Creative)
  • [a].zip;Apple Panic (1982)(Creative)
  • [a];vic_games;Apple Panic (1982)(Creative)
  • [a];;;;;;;;blah;NTSC;;;games



keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Need help (please) with magic token data comparison
« Reply #4 on: August 25, 2020, 03:06:47 AM »
You need to review programming basics. Quick youtube course. Most languages are somewhat similar. JavaScript is a good one close to squirrel. This link might help. Practice declaring variables and functions. Print result to console. https://tio.run/#squirrel

Declared get_memory function.
Comparison block if a variable get_memory is not equal to a string of "blah", then create a text object with a magic function pointing to get_memory function.

Functions and variables are not the same. Your code will never work. Make sure you look at your log in the terminal! AttractMode should not have a windows version suppressing the console, but that is my opinion. Create your object with a magic string function. Within that function, return text.

Code: [Select]
// Here is an example, written from my phone untested.
magic <- function()
{
    return fe.game_info( Info.DisplayCount, 0 , 0 )
}

local text = fe.add_text( [!magic], 0, 0, fe.layout.width, fe.layout.height / 25 )

Retrozz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Need help (please) with magic token data comparison
« Reply #5 on: August 25, 2020, 08:13:49 PM »
Thanks again.. I understand the concept.. but don't know squirrel very well at all.

My last real coding was either x86/68k assembler, and C (not C++) so maybe a bit rusty :)

I assume I can find a quick tutorial on Squirrel itself? I've checked out the squirrel language page as well as having the Attract mode pages at the ready, but it's more of looking up functions as required.

Ultimately what I need is to have as you said.. a function to return to a variable a string OR an integer. Either one is fine. Something I can do a comparison with.

I see your code is doing what appears to be the same as mine in that your returning via function a variable.. which is a string? an integer, an object?

If I utilize the return from my function I can get it to display via fe.add_text as well which would indicate I've returned something (string, integer, object) that AM can process, EXCEPT within an IF statement specifically.

Appreciate the help and patience.. I understand coding basics.. been doing it as a hobby for decades. It's the specifics in Squirrel that seem to have me stymied. It works in all aspects except that darned IF. I tried to .tointeger() to no avail (not using blah obviously but just singular numbers 1-8)

In any event.. thanks for the help. It's very much appreciated.