プレイ日記
Ed CPFace
I'm having some problems with the USE command relating to the scope of my variables. My functions make use of global variables to talk back and forth to one another. Ideally, someone who uses my library should have the option to load it into another slot and USE it from there.
2そうだね
プレイ済み
返信[1]
親投稿
Ed CPFace
I define my variables globally in Slot 0 and USE 1, which contains my library. But when I try to use the function NEWGUI, it gives me a type mismatch error on line 18, where I try to FILL my array. The conclusion I've come to is that my global variables in Slot 0 are out of scope for any functions running from Slot 1.
1そうだね
プレイ済み
返信[2]
親投稿
Ed CPFace
Does anyone know a way to make my variables global across all Slots? The only other solution I can think of is that people will need to copy and paste my functions into their program to get them to work.
1そうだね
プレイ済み
返信[3]
親投稿
Frood Volkanon
A more modular approach is for users to call functions to initialize and modify your data structures indirectly rather than doing it themselves.
1そうだね
プレイ済み
返信[4]
親投稿
Ed CPFace
The problem is that I need these data structures to be visible to an entire family of functions. Passing a structure into a function only passes it by value, and anything defined inside a function is a local variable that's erased when the function ends. I know there are workarounds - DEF FUNC X OUT X - but one of my goals with this library is to make the syntax as simple as possible.
1そうだね
プレイ済み
返信[5]
親投稿
Ed CPFace
If I could give the user a syntax like this: USE 1 INITGUI(MAXELEMENTS) NEWGUI BTN ID,"START",X,Y,#RED ... that would be perfect. But I don't see how I can do that given the way SmileBASIC defines variable scope.
1そうだね
プレイ済み
返信[6]
親投稿
Ed CPFace
I guess there's only so much you can say about the subject without seeing my code, but I do already have sort of "black box" functions that deal with data in a way the programmer never has to see. My trouble is how to create that data in the first place in a way that my functions can see and, if possible, the programmer doesn't have to bother with.
1そうだね
プレイ済み
返信[7]
親投稿
Ed CPFace
I know I'm sort of trying to force OO ideas into a structured environment, and rather inelegantly at that, but if I could make a variable defined in Slot 0 visible to a function in Slot 1, it would at least look very neat to someone using it to write a program. I suspect I'm going to have to ditch rigorous design for ease of use and just have users copy/paste my functions into their programs.
1そうだね
プレイ済み
返信[8]
親投稿
Frood Volkanon
Oh, wow, I didn't realize that other slots don't have their own global variable pool. Sorry I posted under the assumption that they did. I wrote a quick test and my eyes got really big (in surprise, not delight). YUCK.
1そうだね
プレイ済み
返信[9]
親投稿
zag Tall-T
How do I make a sprite move using the circle pad? And not go off the screen? And set the spee?
0そうだね
未プレイ
返信[10]
親投稿
Ed CPFace
@Frood Hey, no problem! Your post IS good general advice. :)
1そうだね
プレイ済み
返信[11]
親投稿
zag Tall-T
Any one know?
0そうだね
未プレイ
返信[12]
親投稿
Ed CPFace
@zag
1そうだね
プレイ済み
返信[13]
親投稿
Ed CPFace
@zag Go to smilebasic.com and check out the full instruction list. Look up the instructions I used here to see their full definitions so that you can learn how to use them to create the effects you want.
1そうだね
プレイ済み
返信[14]
親投稿
calc84 calc84maniac
Maybe try EXEC instead of USE so the arrays get initialized? Ideally that should run the variable initializations and then skip over the function definitions, then return to the previous slot.
0そうだね
プレイ済み
返信[15]
親投稿
Ed CPFace
@calc84 YOU GOT IT! I could have sworn that I tried that already and it didn't work, but... THAT DID IT! I'll have to make some adjustments, but I think I know what to do from here. THANK YOU!
0そうだね
プレイ済み
返信[16]
親投稿
Ed CPFace
@Frood This DOES seem to be the way to give Slot 1 its own variable pool, using EXEC instead of USE. It seems like Slot 1 variables aren't visible in Slot 0 programs, but you should be able to access them through functions.
0そうだね
プレイ済み
返信[17]
親投稿
calc84 calc84maniac
USE does also give slot 1 its variable pool, *but* none of the variables are initialized. The array variables can't be used (except by assigning a reference to an existing array) and number/string variables are left as 0 or the empty string. EXEC fixes this by actually running the initialization lines as a program.
1そうだね
プレイ済み
返信[18]
親投稿
Frood Volkanon
calc84 to the rescue! Next time I won't comment unless I know what I'm talking about. I've given myself a stern reprimand.
0そうだね
プレイ済み
返信[19]
親投稿
Ed CPFace
No sweat, Frood. You *did* have the right idea.
0そうだね
プレイ済み
返信[20]
親投稿
MIKI ifconfig
Difference of USE and EXEC by President Kobayashi: https://miiverse.nintendo.net/replies/AYMHAAACAAADVHkNroE4Lg according to it, "EXEC N" nearly equals to "USE N then RUN N".
1そうだね
未プレイ