I'm making a simple text-based battle between the player and a dragon. I use Menus to have the player select from a set of options. The Menu then obviously goes to the Lbl assigned to the selected option. Within the while loop for the game I can end the Lbls by using the End command to go back to the start of the loop, but when the player chooses the difficulty, there is no loop. How do I prevent all the subsequent Lbls from being executed in this code:
:Menu("DIFFICULTY?", "EASY", 00, "MEDIUM", 01, "HARD", 02)
:Lbl 00
:75->D
://some end statement
:Lbl 01
:150->D
://some end statement
:Lbl 02
:300->D
://some end statement
Because currently, all Labels are executed resulting in the dragon having 300 health no matter the option chosen. (I don't want a work around with scalars or some other trick, I want to know how I can emulate what I described in a general situation so I can use the technique in future programs).
You can add another label at the end and go to it after setting the dragon's health.
Like this:
:Menu("DIFFICULTY?", "EASY", 00, "MEDIUM", 01, "HARD", 02)
:Lbl 00
:75->D
:GoTo 03
:Lbl 01
:150->D
:GoTo 03
:Lbl 02
:300->D
://you don't need a GoTo here since there are no more labels and Lbl 03 is the next line.
:Lbl 03
://The rest of your code...
This will exit out of the switch-style setup you are using and continue with the code.
Personally, I would use an if then, elseIf then, else, endIf block to achieve this goal.
Related
I've been searching for a long time now and I wanted to know,
How can I code that things will happens when I press on a specific key, (e.g. W).
I found many threads that help in this section with general keys like the delete key or the spacebar and some keyDown theKey, but how do I define "theKey"?
Please help,
FESFEW
For the alphanumeric keys you can use as follows:
on keyDown thekey
switch thekey
case "w"
answer "w key pressed"
break
default
pass keyDown
end switch
end keyDown
KeyDown is an event that will be generated each time the user presses a keyboard symbol (not the function keys), the thekey parameter will contain the symbol of the pressed key.
On the other hand, if you want to differentiate capital letters you must set the CaseSensitive property to TRUE
set the caseSensitive to true
The rawKeyDown property works similarly, but instead of coming in the parameter, the symbol of the pressed key what you will get will be the code of the pressed key including the function keys like shift, F# etc.
on rawKeyDown theKeyCode
switch theKeyCode
case 32
answer "SPACE KEY"
break
case 119
answer "w key pressed"
break
default
pass rawKeyDown
end switch
end rawKeyDown
Constants will be very useful to help make your code more readable, adding constants to previous code will look like this (note that the uppercase keys have codes other than the lowercase ):
constant kSpaceKey = 32
constant kwKey = 119
constant kWUpperKey = 87
on rawKeyDown theKeyCode
switch theKeyCode
case kSpaceKey
answer "SPACE KEY"
break
case kwKey
answer "w key pressed"
break
case kwKey
answer "w key pressed"
break
case kWUpperKey
answer "upper W key pressed"
break
default
pass rawKeyDown
end switch
end rawKeyDown
You can also use this script in the card script to show the code of the key you press:
on rawKeyDown theKeyCode
put theKeyCode
end rawKeyDown
Always remember to pass rawKeyDown, rawKeyUp,KeyDown and KeyUp events if you
want to allow them to continue normal message flow
I started a little script using CAPSLock key for navigation (This is only part of the code):
SetCapsLockState, AlwaysOff
CapsLock & i::
if getkeystate("alt") = 0
Send,{Up}
else
Send,+{Up}
return
CapsLock & l::
if getkeystate("alt") = 0
Send,{Right}
else
send, +{Right}
return
It works perfectly everywhere.. except in MS Excel!
When I select a range of cells the selection marquee is there but no cell reference is taken in the formula.
Ex: Summing C3:C10 turns into =sum() no cells are actually selected in the formula.
if I keep trying up and down many times.. it shows, but never consistent.
Any idea how to fix this?
Thank you in advance
The problem comes from your shift key being released between the key presses.
Like for example try pressing keys like this in Excel and you'll see you're not actually selecting cells, you're just highlighting them:
Shift Down, Up Arrow, Shift Up
Shift Down, Up Arrow, Shift Up
Shift Down, Up Arrow, Shift Up
...
So you're going to have to keep shift pressed for the whole duration of your selection making process.
Here's what I could come up with:
CapsLock::Shift
#If, GetKeyState("CapsLock", "P")
*i::
if (GetKeyState("Alt", "P"))
SendInput, {Blind}{Alt Up}{Up}
else
SendInput, {Up}
return
*l::
if (GetKeyState("Alt", "P"))
SendInput, {Blind}{Alt Up}{Right}
else
SendInput, {Down}
return
#If
Or just like this to write it a lot cleaner with a ternary:
CapsLock::Shift
#If, GetKeyState("CapsLock", "P")
*i::SendInput, % GetKeyState("Alt", "P") ? "{Blind}{Alt Up}{Up}" : "{Up}"
*l::SendInput, % GetKeyState("Alt", "P") ? "{Blind}{Alt Up}{Right}" : "{Right}"
#If
So what's happening?
First we use the simple remapping syntax(docs) to remap CapsLock to Shift.
Then we create context sensitive hotkeys for I and L with #If(docs).
The hotkeys are only triggered if the physical state of CapsLock is down.
We need the physical state, because the logical state (which is default) was remapped to shift.
The hotkeys are created with the * modifier(docs) so they fire even if Shift and/or Alt is held down.
I switched the Send commands SendInput due to it being the recommended faster and more reliable send mode(docs).
And then about {Blind}. Normally, when you just send something with a send command, it automatically releases any modifiers you may be holding. But if you use the blind send mode(docs), this doesn't happen. So Shift is still held down all the time.
I made this gantt chart in R using diagrammer::mermaid (reproducible code below):
It is nice, but I would like to:
Increase font size (I suppose this will make each line wider, making the current very long rectangle slightly more "square". I am fine with that)
Make the t-aixis labels more standard. The weeks for some, months for others seem very strange. I want to be able to tell the months and years apart in a concise way)
How can I implement these changes?
I am an R user with no knowledge of node.js, css, etc. I managed to find code snippets on the internet to create this, but do not understand anything about the style_widget or how to change it.
devtools::install_github('rich-iannone/DiagrammeR')
library(DiagrammeR)
library(tidyverse) #just for the pipe operator
style_widget <- function(hw=NULL, style="", addl_selector="") {
stopifnot(!is.null(hw), inherits(hw, "htmlwidget"))
# use current id of htmlwidget if already specified
elementId <- hw$elementId
if(is.null(elementId)) {
# borrow htmlwidgets unique id creator
elementId <- sprintf(
'htmlwidget-%s',
htmlwidgets:::createWidgetId()
)
hw$elementId <- elementId
}
htmlwidgets::prependContent(
hw,
htmltools::tags$style(
sprintf(
"#%s %s {%s}",
elementId,
addl_selector,
style
)
)
)
}
flx_BmP <- mermaid("
gantt
dateFormat YYYY-MM-DD
section Common
Application (1230 plants) :done, first_1, 2018-05-15, 2018-07-30
Elegible (1003) :done, first_1, 2018-06-15, 45d
Plants accept (576) :done, first_1, 2018-08-01, 2d
Q0 - Baseline (576) :done, first_1, 2018-08-02, 15d
Lottery (576) :done, first_1, 2018-09-10, 2d
section ITT (288)
Treated (223 77%) :done, first_2, 2018-09-20, 2018-12-15
Q1 :done, first_3, 2018-12-16, 2019-01-05
Q2 : first_3, 2019-06-01, 2019-06-15
section Control (288)
Q1 :done, first_3, 2018-12-16, 2019-01-05
Q2 : first_3, 2019-06-01, 2019-06-15
Treated (263) : first_3, 2019-06-16, 2019-09-15
") %>%
style_widget("display:none", "line.today")
flx_BmP
For axis format (question 1.), maybe your search for this :
axisFormat %d/%m
Doc : https://mermaidjs.github.io/gantt.html
Example :
gantt
title Gantt
dateFormat DD-MM-YYYY
axisFormat %d/%m
section One
Task One : 07-05-2019, 7d
Task Two : 09-05-2019, 7d
I don't know for the font size.
Link to a demo with your code : https://mermaidjs.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjo...
Within a player, I would like to allow the user to manually drag the boundaries of the selection (start time and end time).
I can use a dragStart message to catch if the user start to drag, but I can't get the final positions of the elements, because I don't know when the user stop to drag.
I have tried something like this:
on dragStart
repeat until the mouse is up
/*unfortunately, this part freeze the player*/
end repeat
put the timeScale of me into sr
put the endTime of me into endT
put endT/sr
end dragStart
But the player is frozen with the wait command. So the user can't move the boundaries, and I can't get the final position of the "endTime".
How to wait until the mouse is up, but without frozen the player?
There are many ways to get out of that blocking loop, waiting "with messages" or sending a message in time within a handler, which releases the engine during the interval. But the most basic might be something like this, if you will try an experiment. Make a button and a field on a new card. In the button script:
on dragStart
put the loc of me into line 1 of fld 1
end dragStart
on mouseMove
if the mouseLoc is within the rect of me and the mouse is down then
set the loc of me to the mouseLoc
end if
end mouseMove
on mouseup
put the loc of me into line 2 of fld 1
end mouse up
Now this is overdone, but at least shows how you can use small handlers to deal with small issues.
This could finally be achieved with a very simple code (as often with livecode):
on selectionchanged
put the timeScale of me into sr
put the endTime of me into endT
put endT/sr into fld 1
end selectionchanged
I want to put a transparent label on top of a sheet in Excel, so that I can take advantage of the MouseMove event of the label to "draw cells" (aka change their fill color and so on) by mouse click / drag / etc. - since I can't do that on the cells per se.
Now everything works just fine, except that I can't make the label transparent at runtime (aka in VBA) ... while by doing exactly the same thing in Design Mode works as expected. Specifically, I have the code (more or less):
Dim MapLabel As OLEObject
On Error Resume Next
Sheet2.OLEObjects("MapLabel").Delete
Set MapLabel = Sheet2.OLEObjects.Add("Forms.Label.1")
MapLabel.name = "MapLabel"
MapLabel.Placement = xlMoveAndSize
MapLabel.Object.Caption = ""
' Problem line below
MapLabel.Object.BackStyle = fmBackStyleTransparent
' Problem line above
MapLabel.Left = Sheet2.cells(2, 6).Left
MapLabel.Top = Sheet2.cells(2, 6).Top
MapLabel.Width = Sheet2.cells(2,6).Width * 10
MapLabel.Height = Sheet2.cells(2,6).Height * 10
So, in words, I first delete the label named 'MapLabel', then recreate it (the above code goes into a "init" Sub). All the code lines except the one marked produce the desired result. The marked one does set the BackStyle property of the label to fmBackStyleTransparent ... but it doesn't actually make the label transparent. This is frustrating, because it's the same approach that works flawlessly at design time!
Do you have a solution to this? I read about solving similar problems by declaring the label as MsForms.Label or as Control, but the sheet object doesn't have those properties, plus, there are far more label properties which can be set using the OLEObject than with the help of MsForms.Label or Control.
All you need to do after this line:
MapLabel.Object.BackStyle = fmBackStyleTransparent
put this line:
ActiveSheet.Shapes(MapLabel.Name).Fill.Transparency = 1
I hope I helped.
P.S. If you need explanation i will edit my answer.
I had the same problem as you but in Word. The solution for me was to do the following:
In design mode:
Right click on the object
Navigate to Switch to automatic form/Image > Wrapping > In front of the text
Add an empty picture to your label